Skip to content

Commit bfb9184

Browse files
committed
This is SF patch #405952, by Anthony Baxter:
cmd.py uses raw_input(); eats SIGCLD: I discovered a rather nasty side effect of the standard cmd.py library today. If it's sitting inside raw_input(), any SIGCLDs that get sent to your application get silently eaten and ignored. I'm assuming that this is something that readline is thoughtfully doing for me. This patch adds an instance attr that allows the user to select to not use raw_input(), but instead use sys.stdin.readline() [Changed slightly to catch EOFError only for raw_input().]
1 parent 4e262a9 commit bfb9184

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

Lib/cmd.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
they automatically support Emacs-like command history and editing features.
3636
"""
3737

38-
import string
38+
import string, sys
3939

4040
__all__ = ["Cmd"]
4141

@@ -54,6 +54,7 @@ class Cmd:
5454
misc_header = "Miscellaneous help topics:"
5555
undoc_header = "Undocumented commands:"
5656
nohelp = "*** No help on %s"
57+
use_rawinput = 1
5758

5859
def __init__(self): pass
5960

@@ -69,10 +70,18 @@ def cmdloop(self, intro=None):
6970
line = self.cmdqueue[0]
7071
del self.cmdqueue[0]
7172
else:
72-
try:
73-
line = raw_input(self.prompt)
74-
except EOFError:
75-
line = 'EOF'
73+
if self.use_rawinput:
74+
try:
75+
line = raw_input(self.prompt)
76+
except EOFError:
77+
line = 'EOF'
78+
else:
79+
sys.stdout.write(self.prompt)
80+
line = sys.stdin.readline()
81+
if not len(line):
82+
line = 'EOF'
83+
else:
84+
line = line[:-1] # chop \n
7685
line = self.precmd(line)
7786
stop = self.onecmd(line)
7887
stop = self.postcmd(stop, line)

0 commit comments

Comments
 (0)