bpo-31804: Fix multiprocessing.Process with broken standard streams (… · python/cpython@e756f66 (original) (raw)
`@@ -584,10 +584,19 @@ def test_wait_for_threads(self):
`
584
584
`self.assertTrue(evt.is_set())
`
585
585
``
586
586
`@classmethod
`
587
``
`-
def _test_error_on_stdio_flush(self, evt):
`
``
587
`+
def _test_error_on_stdio_flush(self, evt, break_std_streams={}):
`
``
588
`+
for stream_name, action in break_std_streams.items():
`
``
589
`+
if action == 'close':
`
``
590
`+
stream = io.StringIO()
`
``
591
`+
stream.close()
`
``
592
`+
else:
`
``
593
`+
assert action == 'remove'
`
``
594
`+
stream = None
`
``
595
`+
setattr(sys, stream_name, None)
`
588
596
`evt.set()
`
589
597
``
590
``
`-
def test_error_on_stdio_flush(self):
`
``
598
`+
def test_error_on_stdio_flush_1(self):
`
``
599
`+
Check that Process works with broken standard streams
`
591
600
`streams = [io.StringIO(), None]
`
592
601
`streams[0].close()
`
593
602
`for stream_name in ('stdout', 'stderr'):
`
`@@ -601,6 +610,24 @@ def test_error_on_stdio_flush(self):
`
601
610
`proc.start()
`
602
611
`proc.join()
`
603
612
`self.assertTrue(evt.is_set())
`
``
613
`+
self.assertEqual(proc.exitcode, 0)
`
``
614
`+
finally:
`
``
615
`+
setattr(sys, stream_name, old_stream)
`
``
616
+
``
617
`+
def test_error_on_stdio_flush_2(self):
`
``
618
`+
Same as test_error_on_stdio_flush_1(), but standard streams are
`
``
619
`+
broken by the child process
`
``
620
`+
for stream_name in ('stdout', 'stderr'):
`
``
621
`+
for action in ('close', 'remove'):
`
``
622
`+
old_stream = getattr(sys, stream_name)
`
``
623
`+
try:
`
``
624
`+
evt = self.Event()
`
``
625
`+
proc = self.Process(target=self._test_error_on_stdio_flush,
`
``
626
`+
args=(evt, {stream_name: action}))
`
``
627
`+
proc.start()
`
``
628
`+
proc.join()
`
``
629
`+
self.assertTrue(evt.is_set())
`
``
630
`+
self.assertEqual(proc.exitcode, 0)
`
604
631
`finally:
`
605
632
`setattr(sys, stream_name, old_stream)
`
606
633
``