[pypy-commit] pypy py3.6: test, fix for return value when stdout, stderr could not be flushed at exit
mattip
pypy.commits at gmail.com
Sun Sep 1 14:42:52 EDT 2019
Author: Matti Picus <matti.picus at gmail.com>
Branch: py3.6
Changeset: r97365:2c1cb3a4c2c5
Date: 2019-09-01 21:42 +0300
http://bitbucket.org/pypy/pypy/changeset/2c1cb3a4c2c5/
Log: test, fix for return value when stdout, stderr could not be flushed
at exit
diff --git a/pypy/goal/targetpypystandalone.py b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -88,7 +88,11 @@
return 1
finally:
try:
- space.finish()
+ # the equivalent of Py_FinalizeEx
+ if space.finish() < 0:
+ # Value unlikely to be confused with a non-error exit status
+ # or other special meaning (from cpython/Modules/main.c)
+ exitcode = 120
except OperationError as e:
debug("OperationError:")
debug(" operror-type: " + e.w_type.getname(space))
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -459,15 +459,18 @@
w_mod.init(self)
def finish(self):
+ ret = 0
self.wait_for_thread_shutdown()
w_atexit = self.getbuiltinmodule('atexit')
self.call_method(w_atexit, '_run_exitfuncs')
self.sys.finalizing = True
- self.sys.flush_std_files(self)
+ if self.sys.flush_std_files(self) < 0:
+ ret = -1
from pypy.interpreter.module import Module
for w_mod in self.builtin_modules.values():
if isinstance(w_mod, Module) and w_mod.startup_called:
w_mod.shutdown(self)
+ return ret
def wait_for_thread_shutdown(self):
"""Wait until threading._shutdown() completes, provided the threading
diff --git a/pypy/interpreter/test/test_app_main.py b/pypy/interpreter/test/test_app_main.py
--- a/pypy/interpreter/test/test_app_main.py
+++ b/pypy/interpreter/test/test_app_main.py
@@ -749,7 +749,7 @@
monkeypatch.setenv('PYTHONWARNINGS_', "once,error")
data = self.run('-W ignore -W default '
'-c "import sys; print(sys.warnoptions)"')
- assert "['ignore', 'default', 'once', 'error']" in data
+ assert "['once', 'error', 'ignore', 'default']" in data
def test_option_m(self, monkeypatch):
if not hasattr(runpy, '_run_module_as_main'):
diff --git a/pypy/interpreter/test/test_objspace.py b/pypy/interpreter/test/test_objspace.py
--- a/pypy/interpreter/test/test_objspace.py
+++ b/pypy/interpreter/test/test_objspace.py
@@ -455,4 +455,14 @@
""")
space.finish()
# assert that we reach this point without getting interrupted
- # by the OperationError(NameError)
+
+ def test_exit_closed_std(self):
+ from pypy.tool.pytest.objspace import maketestobjspace
+ space = maketestobjspace()
+ space.appexec([], """():
+ import sys, os
+ sys.stdout.write('x')
+ os.close(sys.stdout.fileno())
+ """)
+ ret = space.finish()
+ assert ret < 0
diff --git a/pypy/interpreter/test/test_targetpypy.py b/pypy/interpreter/test/test_targetpypy.py
--- a/pypy/interpreter/test/test_targetpypy.py
+++ b/pypy/interpreter/test/test_targetpypy.py
@@ -6,7 +6,7 @@
def test_run(self):
config = get_pypy_config(translating=False)
entry_point = get_entry_point(config)[0]
- entry_point(['pypy3-c' , '-S', '-c', 'print 3'])
+ entry_point(['pypy3-c' , '-S', '-c', 'print(3)'])
def test_execute_source(space):
_, d = create_entry_point(space, None)
More information about the pypy-commit
mailing list