Skip to content

Commit

Permalink
Trac #18908: Fix math-readline script
Browse files Browse the repository at this point in the history
{{{
sage: mathematica(1)
}}}
hangs indefinitely if `Mathematica` is not installed.

The reason is that internally the script `$SAGE_LOCAL/bin/math-readline`
is called by `Expect()`, and the latter hangs. This script should check
whether the `math` command has finished: currently the `math-readline`
script keeps running even after the subprocess has exited.

URL: http://trac.sagemath.org/18908
Reported by: dimpase
Ticket author(s): Jeroen Demeyer
Reviewer(s): Nathann Cohen, Sébastien Labbé, Salvatore Stella, Dima
Pasechnik
  • Loading branch information
Release Manager authored and vbraun committed Jul 17, 2015
2 parents a0311c0 + a3c75ab commit e29390a
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/bin/math-readline
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,27 @@
# See
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/363500

import os, sys
import six
f1 = os.popen('math ', 'w')
f1.flush()
try:
while True:
sys.stdout.write('')
try:
line = six.moves.input()
f1.writelines(line+'\n')
f1.flush()
except KeyboardInterrupt:
f1.close()
break
except EOFError:
pass
import sys, signal, subprocess
import readline
from six.moves import input

def child_exited(*args):
global child
status = child.poll()
if status is not None:
sys.exit(status)

signal.signal(signal.SIGCHLD, child_exited)

child = subprocess.Popen('math', shell=True, stdin=subprocess.PIPE)
pipe = child.stdin
while True:
try:
line = input()
pipe.write(line + '\n')
pipe.flush()
except KeyboardInterrupt:
pipe.close()
except EOFError:
break
sys.stdout.write('\n')
sys.exit()

0 comments on commit e29390a

Please sign in to comment.