Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Lib/multiprocessing/popen_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ class Popen(object):
method = 'fork'

def __init__(self, process_obj):
sys.stdout.flush()
sys.stderr.flush()
try:
sys.stdout.flush()
except (AttributeError, ValueError):
pass
try:
sys.stderr.flush()
except (AttributeError, ValueError):
pass
self.returncode = None
self.finalizer = None
self._launch(process_obj)
Expand Down
21 changes: 21 additions & 0 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,27 @@ def test_wait_for_threads(self):
proc.join()
self.assertTrue(evt.is_set())

@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)


#
#
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix multiprocessing.Process when stdout and/or stderr is closed or None.