Skip to content

Commit 5ce47b9

Browse files
authored
[3.13] gh-133744: Fix multiprocessing interrupt test: add an event (#133746) (#133917)
gh-133744: Fix multiprocessing interrupt test: add an event (#133746) Add an event to synchronize the parent process with the child process: wait until the child process starts sleeping. (cherry picked from commit c2989b7)
1 parent 532acbd commit 5ce47b9

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,11 @@ def _test_process_mainthread_native_id(cls, q):
511511
def _sleep_some(cls):
512512
time.sleep(100)
513513

514+
@classmethod
515+
def _sleep_some_event(cls, event):
516+
event.set()
517+
time.sleep(100)
518+
514519
@classmethod
515520
def _test_sleep(cls, delay):
516521
time.sleep(delay)
@@ -519,7 +524,8 @@ def _kill_process(self, meth):
519524
if self.TYPE == 'threads':
520525
self.skipTest('test not appropriate for {}'.format(self.TYPE))
521526

522-
p = self.Process(target=self._sleep_some)
527+
event = self.Event()
528+
p = self.Process(target=self._sleep_some_event, args=(event,))
523529
p.daemon = True
524530
p.start()
525531

@@ -537,8 +543,11 @@ def _kill_process(self, meth):
537543
self.assertTimingAlmostEqual(join.elapsed, 0.0)
538544
self.assertEqual(p.is_alive(), True)
539545

540-
# XXX maybe terminating too soon causes the problems on Gentoo...
541-
time.sleep(1)
546+
timeout = support.SHORT_TIMEOUT
547+
if not event.wait(timeout):
548+
p.terminate()
549+
p.join()
550+
self.fail(f"event not signaled in {timeout} seconds")
542551

543552
meth(p)
544553

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix multiprocessing interrupt test. Add an event to synchronize the parent
2+
process with the child process: wait until the child process starts
3+
sleeping. Patch by Victor Stinner.

0 commit comments

Comments
 (0)