[Python-checkins] [3.6] bpo-28326: Fix multiprocessing.Process when stdout and/or stderr is closed or None. (GH-4073). (#4075)

Antoine Pitrou webhook-mailer at python.org
Sun Oct 22 06:27:16 EDT 2017


https://github.com/python/cpython/commit/34ef6da8f5fb03b83268bd35b77fb2183c748b70
commit: 34ef6da8f5fb03b83268bd35b77fb2183c748b70
branch: 3.6
author: Antoine Pitrou <pitrou at free.fr>
committer: GitHub <noreply at github.com>
date: 2017年10月22日T12:27:13+02:00
summary:
[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 commit daeefd2e049b74340307481112a39f77de0f4769)
* [3.6] bpo-28326: Fix multiprocessing.Process when stdout and/or stderr is closed or None. (GH-4073).
(cherry picked from commit daeefd2e049b74340307481112a39f77de0f4769)
files:
A Misc/NEWS.d/next/Library/2017-10-22-11-06-02.bpo-28326.rxh7L4.rst
M Lib/multiprocessing/popen_fork.py
M Lib/test/_test_multiprocessing.py
diff --git a/Lib/multiprocessing/popen_fork.py b/Lib/multiprocessing/popen_fork.py
index d2ebd7cfbe1..5d0fa569f12 100644
--- a/Lib/multiprocessing/popen_fork.py
+++ b/Lib/multiprocessing/popen_fork.py
@@ -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._launch(process_obj)
 
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index db30e6b9d22..80c95d6bca6 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -425,6 +425,27 @@ def test_lose_target_ref(self):
 self.assertEqual(q.get(), 5)
 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)
+
 
 #
 #
diff --git a/Misc/NEWS.d/next/Library/2017-10-22-11-06-02.bpo-28326.rxh7L4.rst b/Misc/NEWS.d/next/Library/2017-10-22-11-06-02.bpo-28326.rxh7L4.rst
new file mode 100644
index 00000000000..bcf43bc84c9
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2017-10-22-11-06-02.bpo-28326.rxh7L4.rst
@@ -0,0 +1 @@
+Fix multiprocessing.Process when stdout and/or stderr is closed or None.


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /