[3.6] bpo-31804: Fix multiprocessing.Process with broken standard str… · python/cpython@069b8d2 (original) (raw)

`@@ -427,10 +427,19 @@ def test_lose_target_ref(self):

`

427

427

`close_queue(q)

`

428

428

``

429

429

`@classmethod

`

430

``

`-

def _test_error_on_stdio_flush(self, evt):

`

``

430

`+

def _test_error_on_stdio_flush(self, evt, break_std_streams={}):

`

``

431

`+

for stream_name, action in break_std_streams.items():

`

``

432

`+

if action == 'close':

`

``

433

`+

stream = io.StringIO()

`

``

434

`+

stream.close()

`

``

435

`+

else:

`

``

436

`+

assert action == 'remove'

`

``

437

`+

stream = None

`

``

438

`+

setattr(sys, stream_name, None)

`

431

439

`evt.set()

`

432

440

``

433

``

`-

def test_error_on_stdio_flush(self):

`

``

441

`+

def test_error_on_stdio_flush_1(self):

`

``

442

`+

Check that Process works with broken standard streams

`

434

443

`streams = [io.StringIO(), None]

`

435

444

`streams[0].close()

`

436

445

`for stream_name in ('stdout', 'stderr'):

`

`@@ -444,6 +453,24 @@ def test_error_on_stdio_flush(self):

`

444

453

`proc.start()

`

445

454

`proc.join()

`

446

455

`self.assertTrue(evt.is_set())

`

``

456

`+

self.assertEqual(proc.exitcode, 0)

`

``

457

`+

finally:

`

``

458

`+

setattr(sys, stream_name, old_stream)

`

``

459

+

``

460

`+

def test_error_on_stdio_flush_2(self):

`

``

461

`+

Same as test_error_on_stdio_flush_1(), but standard streams are

`

``

462

`+

broken by the child process

`

``

463

`+

for stream_name in ('stdout', 'stderr'):

`

``

464

`+

for action in ('close', 'remove'):

`

``

465

`+

old_stream = getattr(sys, stream_name)

`

``

466

`+

try:

`

``

467

`+

evt = self.Event()

`

``

468

`+

proc = self.Process(target=self._test_error_on_stdio_flush,

`

``

469

`+

args=(evt, {stream_name: action}))

`

``

470

`+

proc.start()

`

``

471

`+

proc.join()

`

``

472

`+

self.assertTrue(evt.is_set())

`

``

473

`+

self.assertEqual(proc.exitcode, 0)

`

447

474

`finally:

`

448

475

`setattr(sys, stream_name, old_stream)

`

449

476

``