py3: flush std streams before/after running user code in heredoctest.py
authorYuya Nishihara <yuya@tcha.org>
Tue, 16 Oct 2018 07:18:30 +0200
changeset 40318 55fd0fefbec4
parent 40317 6958eb9bdcd6
child 40319 eb131464c805
py3: flush std streams before/after running user code in heredoctest.py Otherwise, things written to stdout.buffer would be interleaved.
tests/heredoctest.py
--- a/tests/heredoctest.py	Tue Oct 16 08:06:17 2018 +0200
+++ b/tests/heredoctest.py	Tue Oct 16 07:18:30 2018 +0200
@@ -2,6 +2,10 @@
 
 import sys
 
+def flush():
+    sys.stdout.flush()
+    sys.stderr.flush()
+
 globalvars = {}
 lines = sys.stdin.readlines()
 while lines:
@@ -15,6 +19,9 @@
             snippet += l[4:]
         c = compile(snippet, '<heredoc>', 'single')
         try:
+            flush()
             exec(c, globalvars)
+            flush()
         except Exception as inst:
+            flush()
             print(repr(inst))