mirror of
https://github.com/python/cpython.git
synced 2025-09-30 12:21:51 +00:00
[3.6] bpo-28326: Fix multiprocessing.Process when stdout and/or stderr is closed or None. (GH-4073). (#4075)
* bpo-28326: Fix multiprocessing.Process when stdout and/or stderr is closed or None. (#4073) (cherry picked from commitdaeefd2e04
) * [3.6] bpo-28326: Fix multiprocessing.Process when stdout and/or stderr is closed or None. (GH-4073). (cherry picked from commitdaeefd2e04
)
This commit is contained in:
parent
1e78ed6825
commit
34ef6da8f5
3 changed files with 30 additions and 2 deletions
|
@ -14,8 +14,14 @@ class Popen(object):
|
||||||
method = 'fork'
|
method = 'fork'
|
||||||
|
|
||||||
def __init__(self, process_obj):
|
def __init__(self, process_obj):
|
||||||
|
try:
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
except (AttributeError, ValueError):
|
||||||
|
pass
|
||||||
|
try:
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
except (AttributeError, ValueError):
|
||||||
|
pass
|
||||||
self.returncode = None
|
self.returncode = None
|
||||||
self._launch(process_obj)
|
self._launch(process_obj)
|
||||||
|
|
||||||
|
|
|
@ -425,6 +425,27 @@ class _TestProcess(BaseTestCase):
|
||||||
self.assertEqual(q.get(), 5)
|
self.assertEqual(q.get(), 5)
|
||||||
close_queue(q)
|
close_queue(q)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _test_error_on_stdio_flush(self, evt):
|
||||||
|
evt.set()
|
||||||
|
|
||||||
|
def test_error_on_stdio_flush(self):
|
||||||
|
streams = [io.StringIO(), None]
|
||||||
|
streams[0].close()
|
||||||
|
for stream_name in ('stdout', 'stderr'):
|
||||||
|
for stream in streams:
|
||||||
|
old_stream = getattr(sys, stream_name)
|
||||||
|
setattr(sys, stream_name, stream)
|
||||||
|
try:
|
||||||
|
evt = self.Event()
|
||||||
|
proc = self.Process(target=self._test_error_on_stdio_flush,
|
||||||
|
args=(evt,))
|
||||||
|
proc.start()
|
||||||
|
proc.join()
|
||||||
|
self.assertTrue(evt.is_set())
|
||||||
|
finally:
|
||||||
|
setattr(sys, stream_name, old_stream)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix multiprocessing.Process when stdout and/or stderr is closed or None.
|
Loading…
Add table
Add a link
Reference in a new issue