Skip to content

Commit 26d81a3

Browse files
committed
Ensure the tracker is killed to allow multiple testing runs in the same process
1 parent 4f9babb commit 26d81a3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4473,19 +4473,24 @@ def check_semaphore_tracker_death(self, signum, should_die):
44734473
# bpo-31310: if the semaphore tracker process has died, it should
44744474
# be restarted implicitly.
44754475
from multiprocessing.semaphore_tracker import _semaphore_tracker
4476+
pid = _semaphore_tracker._pid
4477+
if pid:
4478+
os.kill(pid, signal.SIGKILL)
4479+
time.sleep(0.5) # give it time to die
44764480
old_stderr = sys.stderr
44774481
r, w = os.pipe()
44784482
try:
44794483
sys.stderr = open(w, "bw")
4480-
_semaphore_tracker.ensure_running()
4484+
with warnings.catch_warnings(record=True) as all_warn:
4485+
_semaphore_tracker.ensure_running()
44814486
pid = _semaphore_tracker._pid
44824487
# Wait until we receive the PONG from the child, indicating that
44834488
# the signal handlers have been registered. See bpo-33613 for more
44844489
# information.
44854490
_semaphore_tracker._send("PING", "")
44864491
with open(r, "rb") as pipe:
44874492
data = pipe.readline()
4488-
if b"PON" not in data:
4493+
if b"PONG" not in data:
44894494
raise ValueError("Invalid data in stderr!")
44904495
finally:
44914496
sys.stderr.close()

0 commit comments

Comments
 (0)