mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[3.14] gh-133744: Fix multiprocessing interrupt test: add an event (GH-133746) (#133916)
gh-133744: Fix multiprocessing interrupt test: add an event (GH-133746)
Add an event to synchronize the parent process with the child
process: wait until the child process starts sleeping.
(cherry picked from commit c2989b7070
)
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
94938caf35
commit
f5d2d73995
2 changed files with 19 additions and 5 deletions
|
@ -513,9 +513,14 @@ class _TestProcess(BaseTestCase):
|
||||||
time.sleep(100)
|
time.sleep(100)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sleep_no_int_handler(cls):
|
def _sleep_some_event(cls, event):
|
||||||
|
event.set()
|
||||||
|
time.sleep(100)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _sleep_no_int_handler(cls, event):
|
||||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||||
cls._sleep_some()
|
cls._sleep_some_event(event)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _test_sleep(cls, delay):
|
def _test_sleep(cls, delay):
|
||||||
|
@ -525,7 +530,10 @@ class _TestProcess(BaseTestCase):
|
||||||
if self.TYPE == 'threads':
|
if self.TYPE == 'threads':
|
||||||
self.skipTest('test not appropriate for {}'.format(self.TYPE))
|
self.skipTest('test not appropriate for {}'.format(self.TYPE))
|
||||||
|
|
||||||
p = self.Process(target=target or self._sleep_some)
|
event = self.Event()
|
||||||
|
if not target:
|
||||||
|
target = self._sleep_some_event
|
||||||
|
p = self.Process(target=target, args=(event,))
|
||||||
p.daemon = True
|
p.daemon = True
|
||||||
p.start()
|
p.start()
|
||||||
|
|
||||||
|
@ -543,8 +551,11 @@ class _TestProcess(BaseTestCase):
|
||||||
self.assertTimingAlmostEqual(join.elapsed, 0.0)
|
self.assertTimingAlmostEqual(join.elapsed, 0.0)
|
||||||
self.assertEqual(p.is_alive(), True)
|
self.assertEqual(p.is_alive(), True)
|
||||||
|
|
||||||
# XXX maybe terminating too soon causes the problems on Gentoo...
|
timeout = support.SHORT_TIMEOUT
|
||||||
time.sleep(1)
|
if not event.wait(timeout):
|
||||||
|
p.terminate()
|
||||||
|
p.join()
|
||||||
|
self.fail(f"event not signaled in {timeout} seconds")
|
||||||
|
|
||||||
meth(p)
|
meth(p)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Fix multiprocessing interrupt test. Add an event to synchronize the parent
|
||||||
|
process with the child process: wait until the child process starts
|
||||||
|
sleeping. Patch by Victor Stinner.
|
Loading…
Add table
Add a link
Reference in a new issue