Skip to content

gh-133744: Fix multiprocessing interrupt test: add an event #133746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,14 @@ def _sleep_some(cls):
time.sleep(100)

@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)
cls._sleep_some()
cls._sleep_some_event(event)

@classmethod
def _test_sleep(cls, delay):
Expand All @@ -525,7 +530,10 @@ def _kill_process(self, meth, target=None):
if self.TYPE == 'threads':
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.start()

Expand All @@ -543,8 +551,11 @@ def _kill_process(self, meth, target=None):
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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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