Author: Antonio Cuni <[email protected]>
Branch:
Changeset: r266:1a94ebdc7c32
Date: 2019-04-16 16:13 +0200
http://bitbucket.org/pypy/pyrepl/changeset/1a94ebdc7c32/
Log: make sure to flush stdout/stderr when calling
readline()/raw_input(). It helps to mitigates this pytest issue:
https://github.com/pytest-dev/pytest/issues/5134
Prior to this fix, pdb++ failed to display the output when you run
it under the conditions described in the issue above.
diff --git a/pyrepl/readline.py b/pyrepl/readline.py
--- a/pyrepl/readline.py
+++ b/pyrepl/readline.py
@@ -181,11 +181,19 @@
saved_history_length = -1
startup_hook = None
config = ReadlineConfig()
+ stdin = None
+ stdout = None
+ stderr = None
def __init__(self, f_in=None, f_out=None):
self.f_in = f_in if f_in is not None else os.dup(0)
self.f_out = f_out if f_out is not None else os.dup(1)
+ def setup_std_streams(self, stdin, stdout, stderr):
+ self.stdin = stdin
+ self.stdout = stdout
+ self.stderr = stderr
+
def get_reader(self):
if self.reader is None:
console = UnixConsole(self.f_in, self.f_out, encoding=ENCODING)
@@ -198,7 +206,18 @@
reader = self.get_reader()
except _error:
return _old_raw_input(prompt)
- reader.ps1 = prompt
+
+ # the builtin raw_input calls PyOS_StdioReadline, which flushes
+ # stdout/stderr before displaying the prompt. Try to mimic this
+ # behavior: it seems to be the correct thing to do, and moreover it
+ # mitigates this pytest issue:
+ # https://github.com/pytest-dev/pytest/issues/5134
+ if self.stdout and hasattr(self.stdout, 'flush'):
+ self.stdout.flush()
+ if self.stderr and hasattr(self.stderr, 'flush'):
+ self.stderr.flush()
+
+ reader.ps1 = prompt
return reader.readline(startup_hook=self.startup_hook)
def multiline_input(self, more_lines, ps1, ps2, returns_unicode=False):
@@ -405,6 +424,7 @@
_wrapper.f_in = f_in
_wrapper.f_out = f_out
+ _wrapper.setup_std_streams(sys.stdin, sys.stdout, sys.stderr)
if '__pypy__' in sys.builtin_module_names: # PyPy
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit