Kaydet (Commit) bfb9184b authored tarafından Guido van Rossum's avatar Guido van Rossum

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().]
üst 4e262a96
...@@ -35,7 +35,7 @@ These interpreters use raw_input; thus, if the readline module is loaded, ...@@ -35,7 +35,7 @@ These interpreters use raw_input; thus, if the readline module is loaded,
they automatically support Emacs-like command history and editing features. they automatically support Emacs-like command history and editing features.
""" """
import string import string, sys
__all__ = ["Cmd"] __all__ = ["Cmd"]
...@@ -54,6 +54,7 @@ class Cmd: ...@@ -54,6 +54,7 @@ class Cmd:
misc_header = "Miscellaneous help topics:" misc_header = "Miscellaneous help topics:"
undoc_header = "Undocumented commands:" undoc_header = "Undocumented commands:"
nohelp = "*** No help on %s" nohelp = "*** No help on %s"
use_rawinput = 1
def __init__(self): pass def __init__(self): pass
...@@ -69,10 +70,18 @@ class Cmd: ...@@ -69,10 +70,18 @@ class Cmd:
line = self.cmdqueue[0] line = self.cmdqueue[0]
del self.cmdqueue[0] del self.cmdqueue[0]
else: else:
try: if self.use_rawinput:
line = raw_input(self.prompt) try:
except EOFError: line = raw_input(self.prompt)
line = 'EOF' except EOFError:
line = 'EOF'
else:
sys.stdout.write(self.prompt)
line = sys.stdin.readline()
if not len(line):
line = 'EOF'
else:
line = line[:-1] # chop \n
line = self.precmd(line) line = self.precmd(line)
stop = self.onecmd(line) stop = self.onecmd(line)
stop = self.postcmd(stop, line) stop = self.postcmd(stop, line)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment