mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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 c2989b7070
)
This commit is contained in:
parent
532acbd0fa
commit
5ce47b96b0
2 changed files with 15 additions and 3 deletions
|
@ -511,6 +511,11 @@ class _TestProcess(BaseTestCase):
|
|||
def _sleep_some(cls):
|
||||
time.sleep(100)
|
||||
|
||||
@classmethod
|
||||
def _sleep_some_event(cls, event):
|
||||
event.set()
|
||||
time.sleep(100)
|
||||
|
||||
@classmethod
|
||||
def _test_sleep(cls, delay):
|
||||
time.sleep(delay)
|
||||
|
@ -519,7 +524,8 @@ class _TestProcess(BaseTestCase):
|
|||
if self.TYPE == 'threads':
|
||||
self.skipTest('test not appropriate for {}'.format(self.TYPE))
|
||||
|
||||
p = self.Process(target=self._sleep_some)
|
||||
event = self.Event()
|
||||
p = self.Process(target=self._sleep_some_event, args=(event,))
|
||||
p.daemon = True
|
||||
p.start()
|
||||
|
||||
|
@ -537,8 +543,11 @@ class _TestProcess(BaseTestCase):
|
|||
self.assertTimingAlmostEqual(join.elapsed, 0.0)
|
||||
self.assertEqual(p.is_alive(), True)
|
||||
|
||||
# XXX maybe terminating too soon causes the problems on Gentoo...
|
||||
time.sleep(1)
|
||||
timeout = support.SHORT_TIMEOUT
|
||||
if not event.wait(timeout):
|
||||
p.terminate()
|
||||
p.join()
|
||||
self.fail(f"event not signaled in {timeout} seconds")
|
||||
|
||||
meth(p)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue