1 new commit in py:
https://bitbucket.org/hpk42/py/commits/a990113bb086/
Changeset: a990113bb086
User: hpk42
Date: 2014-07-05 17:15:46
Summary: make sure that forked functions run with auto-flushing
stdout/stderr
so that if they segfault we get to see stdout/stderr.
Affected #: 5 files
diff -r 6698f8b49b78c6489c932ce95ebda8dac2a3655d -r
a990113bb086420f36489082fdc5220f46c6f8d0 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -5,6 +5,10 @@
methods to allow adding information in the boxed process.
Thanks Marc Schlaich.
+- ForkedFunc in the child opens in "auto-flush" mode for
+ stdout/stderr so that when a subprocess dies you can see
+ its output even if it didn't flush itself.
+
- refactor traceback generation in light of pytest issue 364
(shortening tracebacks). you can now set a new traceback style
on a per-entry basis such that a caller can force entries to be
diff -r 6698f8b49b78c6489c932ce95ebda8dac2a3655d -r
a990113bb086420f36489082fdc5220f46c6f8d0 py/__init__.py
--- a/py/__init__.py
+++ b/py/__init__.py
@@ -8,7 +8,7 @@
(c) Holger Krekel and others, 2004-2013
"""
-__version__ = '1.4.21.dev2'
+__version__ = '1.4.21.dev3'
from py import _apipkg
diff -r 6698f8b49b78c6489c932ce95ebda8dac2a3655d -r
a990113bb086420f36489082fdc5220f46c6f8d0 py/_process/forkedfunc.py
--- a/py/_process/forkedfunc.py
+++ b/py/_process/forkedfunc.py
@@ -36,6 +36,19 @@
sys.stderr.flush()
+def get_unbuffered_io(fd, filename):
+ f = open(str(filename), "w")
+ if fd != f.fileno():
+ os.dup2(f.fileno(), fd)
+ class AutoFlush:
+ def write(self, data):
+ f.write(data)
+ f.flush()
+ def __getattr__(self, name):
+ return getattr(f, name)
+ return AutoFlush()
+
+
class ForkedFunc(HookMixin):
EXITSTATUS_EXCEPTION = 3
@@ -63,14 +76,8 @@
def _child(self, nice_level):
# right now we need to call a function, but first we need to
# map all IO that might happen
- sys.stdout = stdout = open(str(self.STDOUT), "w")
- fdstdout = stdout.fileno()
- if fdstdout != 1:
- os.dup2(fdstdout, 1)
- sys.stderr = stderr = open(str(self.STDERR), "w")
- fdstderr = stderr.fileno()
- if fdstderr != 2:
- os.dup2(fdstderr, 2)
+ sys.stdout = stdout = get_unbuffered_io(1, self.STDOUT)
+ sys.stderr = stderr = get_unbuffered_io(2, self.STDERR)
retvalf = self.RETVAL.open("wb")
EXITSTATUS = 0
try:
diff -r 6698f8b49b78c6489c932ce95ebda8dac2a3655d -r
a990113bb086420f36489082fdc5220f46c6f8d0 setup.py
--- a/setup.py
+++ b/setup.py
@@ -7,7 +7,7 @@
name='py',
description='library with cross-python path, ini-parsing, io, code,
log facilities',
long_description = open('README.txt').read(),
- version='1.4.21.dev2',
+ version='1.4.21.dev3',
url='http://pylib.readthedocs.org/',
license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
diff -r 6698f8b49b78c6489c932ce95ebda8dac2a3655d -r
a990113bb086420f36489082fdc5220f46c6f8d0 testing/process/test_forkedfunc.py
--- a/testing/process/test_forkedfunc.py
+++ b/testing/process/test_forkedfunc.py
@@ -56,6 +56,15 @@
assert result.out == "s"
+def test_forkedfunc_on_stdout():
+ def boxf3():
+ import sys
+ sys.stdout.write("hello\n")
+ os.kill(os.getpid(), 11)
+ result = py.process.ForkedFunc(boxf3).waitfinish()
+ assert result.signal == 11
+ assert result.out == "hello\n"
+
def test_forkedfunc_signal():
result = py.process.ForkedFunc(boxseg).waitfinish()
assert result.retval is None
Repository URL: https://bitbucket.org/hpk42/py/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
_______________________________________________
pytest-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-commit