Skip to content

Commit

Permalink
Trac #33907: interfaces/expect.py random test failure
Browse files Browse the repository at this point in the history
I've been getting this very frequently when running tests under heavy
CPU load. This happens on Sage 9.5 too.

{{{
sage -t --long --random-seed=233407191301051614325254530123917684827
/nix/store/fmcggxb3m1xvlsdqmi045p87xml9paca-sage-
src-9.6/src/sage/interfaces/expect.py
**********************************************************************
File "/nix/store/fmcggxb3m1xvlsdqmi045p87xml9paca-sage-
src-9.6/src/sage/interfaces/expect.py", line 920, in
sage.interfaces.expect.Expect._eval_line
Failed example:
    singular.interrupt()
Expected:
    True
Got:
    False
**********************************************************************
File "/nix/store/fmcggxb3m1xvlsdqmi045p87xml9paca-sage-
src-9.6/src/sage/interfaces/expect.py", line 926, in
sage.interfaces.expect.Expect._eval_line
Failed example:
    singular('2+3')
Expected:
    Singular crashed -- automatically restarting.
    5
Got:
    5
}}}

URL: https://trac.sagemath.org/33907
Reported by: gh-collares
Ticket author(s): Gonzalo Tornaría
Reviewer(s): Matthias Koeppe
  • Loading branch information
Release Manager committed Dec 21, 2022
2 parents 6640924 + 6f5c1c2 commit 962177a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/sage/interfaces/expect.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,6 @@ def _eval_line(self, line, allow_use_file=True, wait_for_prompt=True, restart_if
The interface still works after this interrupt::
sage: singular('2+3')
Singular crashed -- automatically restarting.
5
Last, we demonstrate that by default the execution of a command
Expand Down
47 changes: 47 additions & 0 deletions src/sage/interfaces/singular.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@
import sys
import pexpect
import shlex
import time

from .expect import Expect, ExpectElement, FunctionElement, ExpectFunction

Expand Down Expand Up @@ -508,6 +509,52 @@ def _quit_string(self):
"""
return 'quit;'

def _send_interrupt(self):
"""
Send an interrupt to Singular. If needed, additional
semi-colons are sent until we get back at the prompt.
TESTS:
The following works without restarting Singular::
sage: a = singular(1)
sage: _ = singular._expect.sendline('while(1){};')
sage: singular.interrupt()
True
We can still access a::
sage: 2*a
2
Interrupting nothing or unfinished input also works::
sage: singular.interrupt()
True
sage: _ = singular._expect.sendline('1+')
sage: singular.interrupt()
True
sage: 3*a
3
"""
# Work around for Singular bug
# http://www.singular.uni-kl.de:8002/trac/ticket/727
time.sleep(0.1)

E = self._expect
E.sendline(chr(3))
# The following is needed so interrupt() works even when
# there is no computation going on.
for i in range(5):
try:
E.expect_upto(self._prompt, timeout=0.1)
return
except pexpect.TIMEOUT:
pass
E.sendline(";")

def _read_in_file_command(self, filename):
r"""
EXAMPLES::
Expand Down

0 comments on commit 962177a

Please sign in to comment.