# HG changeset patch
# User Jeroen Demeyer <jdemeyer@cage.ugent.be>
# Date 1340054804 -7200
# Node ID 9a18427412c38840e0a8a410fb96826cdf28cff3
# Parent 8c16c23faac0e48277d86b528fd83913982a322d
Fix interrupting Singular
diff --git a/sage/interfaces/expect.py b/sage/interfaces/expect.py
a
|
b
|
|
568 | 568 | return |
569 | 569 | |
570 | 570 | def _quit_string(self): |
| 571 | """ |
| 572 | Return the string which will be used to quit the application. |
| 573 | |
| 574 | EXAMPLES:: |
| 575 | |
| 576 | sage: gp._quit_string() |
| 577 | '\\q' |
| 578 | sage: maxima._quit_string() |
| 579 | 'quit();' |
| 580 | """ |
571 | 581 | return 'quit' |
572 | 582 | |
| 583 | def _send_interrupt(self): |
| 584 | """ |
| 585 | Send an interrupt to the application. This is used internally |
| 586 | by :meth:`interrupt`. |
| 587 | """ |
| 588 | self._expect.sendline(self._quit_string()) |
| 589 | self._expect.sendline(chr(3)) |
| 590 | |
573 | 591 | def _local_tmpfile(self): |
574 | 592 | """ |
575 | 593 | Return a filename that is used to buffer long command lines for this interface |
… |
… |
|
829 | 847 | sage: singular._eval_using_file_cutoff = 4 |
830 | 848 | sage: singular._eval_line('for(int i=1;i<=3;i++){i=1;};', wait_for_prompt=False) |
831 | 849 | '' |
832 | | sage: singular.interrupt(timeout=3) # sometimes very slow (up to 60s on sage.math, 2012) |
833 | | False |
| 850 | sage: singular.interrupt() |
| 851 | True |
834 | 852 | sage: singular._eval_using_file_cutoff = cutoff |
835 | 853 | |
836 | 854 | Last, we demonstrate that by default the execution of a command |
… |
… |
|
933 | 951 | success = False |
934 | 952 | try: |
935 | 953 | for i in range(tries): |
936 | | E.sendline(self._quit_string()) |
937 | | E.sendline(chr(3)) |
| 954 | self._send_interrupt() |
938 | 955 | try: |
939 | 956 | E.expect(self._prompt, timeout=timeout) |
940 | 957 | success= True |
diff --git a/sage/interfaces/singular.py b/sage/interfaces/singular.py
a
|
b
|
|
9 | 9 | singular(...), x.[tab] includes all singular commands. |
10 | 10 | |
11 | 11 | - Martin Albrecht (2006-03-06): This patch adds the equality symbol to |
12 | | |
| 12 | singular. Also fix problem in which " " as prompt means comparison |
13 | 13 | will break all further communication with Singular. |
14 | 14 | |
15 | 15 | - Martin Albrecht (2006-03-13): added current_ring() and |
… |
… |
|
373 | 373 | Expect.__init__(self, |
374 | 374 | name = 'singular', |
375 | 375 | prompt = prompt, |
376 | | command = "Singular -t --ticks-per-sec 1000", #no tty and fine grained cputime() |
| 376 | # No tty, fine grained cputime(), don't display CTRL-C prompt |
| 377 | command = "Singular -t --ticks-per-sec 1000 --cntrlc=a", |
377 | 378 | maxread = maxread, |
378 | 379 | server = server, |
379 | 380 | server_tmpdir = server_tmpdir, |
… |
… |
|
455 | 456 | """ |
456 | 457 | return 'quit' |
457 | 458 | |
| 459 | def _send_interrupt(self): |
| 460 | """ |
| 461 | Send an interrupt and a semi-colon to Singular. |
| 462 | |
| 463 | TESTS: |
| 464 | |
| 465 | The semi-colon is needed to abort the current input line. The |
| 466 | following works without restarting Singular:: |
| 467 | |
| 468 | sage: from sage.tests.interrupt import interrupt_after_delay |
| 469 | sage: a = singular(1) |
| 470 | sage: _ = singular._expect.sendline('1+') # unfinished input |
| 471 | sage: try: |
| 472 | ... interrupt_after_delay() |
| 473 | ... singular._expect_expr('>') # interrupt this |
| 474 | ... except KeyboardInterrupt: |
| 475 | ... pass |
| 476 | Control-C pressed. Interrupting Singular. Please wait a few seconds... |
| 477 | |
| 478 | We can still access a:: |
| 479 | |
| 480 | sage: 2*a |
| 481 | 2 |
| 482 | """ |
| 483 | E = self._expect |
| 484 | E.sendline(chr(3)) |
| 485 | E.sendline(';') |
| 486 | |
458 | 487 | def _read_in_file_command(self, filename): |
459 | 488 | r""" |
460 | 489 | EXAMPLES:: |