Skip to content

Commit a7d5c59

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

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4479,19 +4479,32 @@ def check_semaphore_tracker_death(self, signum, should_die):
44794479
time.sleep(0.5) # give it time to die
44804480
old_stderr = sys.stderr
44814481
r, w = os.pipe()
4482+
# Make the pipe non blocking to not hang indefinitely
4483+
if sys.platform != "win32":
4484+
import fcntl
4485+
fcntl.fcntl(r, fcntl.F_SETFL,
4486+
fcntl.fcntl(r, fcntl.F_GETFL) | os.O_NONBLOCK)
4487+
sys.stderr = open(w, "bw")
44824488
try:
4483-
sys.stderr = open(w, "bw")
44844489
with warnings.catch_warnings(record=True) as all_warn:
44854490
_semaphore_tracker.ensure_running()
44864491
pid = _semaphore_tracker._pid
44874492
# Wait until we receive the PONG from the child, indicating that
44884493
# the signal handlers have been registered. See bpo-33613 for more
44894494
# information.
44904495
_semaphore_tracker._send("PING", "")
4496+
deadline = time.monotonic() + 5
44914497
with open(r, "rb") as pipe:
4492-
data = pipe.readline()
4493-
if b"PONG" not in data:
4494-
raise ValueError("Invalid data in stderr!")
4498+
while True:
4499+
if time.monotonic() >= deadline:
4500+
raise TimeoutError("Reading data "
4501+
"from pipe took too long")
4502+
data = pipe.readline()
4503+
if not data:
4504+
continue
4505+
if b"PONG" not in data:
4506+
raise ValueError("Invalid data in stderr!")
4507+
break
44954508
finally:
44964509
sys.stderr.close()
44974510
sys.stderr = old_stderr

0 commit comments

Comments
 (0)