Commit 9f56eed9 authored by Jason Madden's avatar Jason Madden

Do not support patch_sys under Py3 because of differences in the interpreter...

Do not support patch_sys under Py3 because of differences in the interpreter that make the current approach using a threadpool unworkable. Fixes test__issue6.
parent cd483e90
......@@ -307,6 +307,7 @@ class FileObjectThread(object):
if line:
return line
raise StopIteration
__next__ = next
FileObjectClosed = IOError(EBADF, 'Bad file descriptor (FileObject was closed)')
......
......@@ -17,9 +17,11 @@ __all__ = ['patch_all',
if sys.version_info[0] >= 3:
string_types = str,
PY3 = True
else:
import __builtin__
string_types = __builtin__.basestring
PY3 = False
# maps module name -> attribute name -> original item
......@@ -85,6 +87,20 @@ def _patch_sys_std(name):
def patch_sys(stdin=True, stdout=True, stderr=True):
"""Patch sys.std[in,out,err] to use a cooperative IO via a threadpool.
This is relatively dangerous and can have unintended consequences such as hanging
the process or misinterpreting control keys.
This method does nothing on Python 3. The Python 3 interpreter wants to flush
the TextIOWrapper objects that make up stderr/stdout at shutdown time, but
using a threadpool at that time leads to a hang.
"""
# test__issue6.py demonstrates the hang if these lines are removed;
# strangely enough that test passes even without monkey-patching sys
if PY3:
return
if stdin:
_patch_sys_std('stdin')
if stdout:
......
......@@ -8,8 +8,8 @@ if not sys.argv[1:]:
out, err = p.communicate(b'hello world\n')
code = p.poll()
assert p.poll() == 0, (out, err, code)
assert out.strip() == '11 chars.', (out, err, code)
assert err == '', (out, err, code)
assert out.strip() == b'11 chars.', (out, err, code)
assert err == b'', (out, err, code)
elif sys.argv[1:] == ['subprocess']:
import gevent
......
......@@ -11,8 +11,6 @@ PY3 = sys.version_info[0] >= 3
FAILING_TESTS = [
# needs investigating
'FLAKY test__issue6.py',
# Sometimes fails with AssertionError: ...\nIOError: close() called during concurrent operation on the same file object.\n'
# Sometimes it contains "\nUnhandled exception in thread started by \nsys.excepthook is missing\nlost sys.stderr\n"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment