diff -r 07c593845994 Lib/multiprocessing/popen_fork.py --- a/Lib/multiprocessing/popen_fork.py Sat Oct 01 22:05:07 2016 -0400 +++ b/Lib/multiprocessing/popen_fork.py Sun Oct 02 04:34:07 2016 +0000 @@ -14,8 +14,10 @@ method = 'fork' def __init__(self, process_obj): - sys.stdout.flush() - sys.stderr.flush() + if not sys.stdout.closed: + sys.stdout.flush() + if not sys.stderr.closed: + sys.stderr.flush() self.returncode = None self._launch(process_obj) diff -r 07c593845994 Lib/test/test_multiprocessing_main_handling.py --- a/Lib/test/test_multiprocessing_main_handling.py Sat Oct 01 22:05:07 2016 -0400 +++ b/Lib/test/test_multiprocessing_main_handling.py Sun Oct 02 04:34:07 2016 +0000 @@ -38,7 +38,7 @@ import sys import time -from multiprocessing import Pool, set_start_method +from multiprocessing import Pool, Process, set_start_method # We use this __main__ defined function in the map call below in order to # check that multiprocessing in correctly running the unguarded @@ -65,6 +65,13 @@ raise RuntimeError("Timed out waiting for results") results.sort() print(start_method, "->", results) + sys.stdout.close() + sys.stderr.close() + process = Process(target=f, args=(1,)) + process.start() + process.join(10) + if process.is_alive(): + raise RuntimeError("Timed out waiting for single process") """ test_source_main_skipped_in_children = """\