[pypy-commit] pypy default: Issue #2837
arigo
pypy.commits at gmail.com
Thu Jul 5 11:02:54 EDT 2018
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r94805:6ee028a07651
Date: 2018-07-05 17:01 +0200
http://bitbucket.org/pypy/pypy/changeset/6ee028a07651/
Log: Issue #2837
Write an end-of-line and flush stdout when an exception is about to
be printed in code.py. Needed to emulate CPython's interactive
command line behaviour more closely, and good to avoid strange
effects.
diff --git a/lib-python/2.7/code.py b/lib-python/2.7/code.py
--- a/lib-python/2.7/code.py
+++ b/lib-python/2.7/code.py
@@ -104,6 +104,12 @@
except SystemExit:
raise
except:
+ if softspace(sys.stdout, 0):
+ print
+ try:
+ sys.stdout.flush()
+ except:
+ pass
self.showtraceback()
else:
if softspace(sys.stdout, 0):
diff --git a/pypy/module/test_lib_pypy/test_code_extra.py b/pypy/module/test_lib_pypy/test_code_extra.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/test_lib_pypy/test_code_extra.py
@@ -0,0 +1,19 @@
+import py
+import sys
+import cStringIO
+import code
+
+
+def test_flush_stdout_on_error():
+ runner = code.InteractiveInterpreter()
+ old_stdout = sys.stdout
+ try:
+ mystdout = cStringIO.StringIO()
+ sys.stdout = mystdout
+ runner.runcode(compile("print 5,;0/0", "<interactive>", "exec"))
+ finally:
+ sys.stdout = old_stdout
+
+ if '__pypy__' not in sys.builtin_module_names:
+ py.test.skip('pypy only test')
+ assert mystdout.getvalue() == "5\n"
More information about the pypy-commit
mailing list