Skip to content

Commit

Permalink
fixup! Ensure the tracker is killed to allow multiple testing runs in…
Browse files Browse the repository at this point in the history
… the same process
  • Loading branch information
pablogsal committed Jul 7, 2018
1 parent 26d81a3 commit a7d5c59
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4479,19 +4479,32 @@ def check_semaphore_tracker_death(self, signum, should_die):
time.sleep(0.5) # give it time to die
old_stderr = sys.stderr
r, w = os.pipe()
# Make the pipe non blocking to not hang indefinitely
if sys.platform != "win32":
import fcntl
fcntl.fcntl(r, fcntl.F_SETFL,
fcntl.fcntl(r, fcntl.F_GETFL) | os.O_NONBLOCK)
sys.stderr = open(w, "bw")
try:
sys.stderr = open(w, "bw")
with warnings.catch_warnings(record=True) as all_warn:
_semaphore_tracker.ensure_running()
pid = _semaphore_tracker._pid
# Wait until we receive the PONG from the child, indicating that
# the signal handlers have been registered. See bpo-33613 for more
# information.
_semaphore_tracker._send("PING", "")
deadline = time.monotonic() + 5
with open(r, "rb") as pipe:
data = pipe.readline()
if b"PONG" not in data:
raise ValueError("Invalid data in stderr!")
while True:
if time.monotonic() >= deadline:
raise TimeoutError("Reading data "
"from pipe took too long")
data = pipe.readline()
if not data:
continue
if b"PONG" not in data:
raise ValueError("Invalid data in stderr!")
break
finally:
sys.stderr.close()
sys.stderr = old_stderr
Expand Down

0 comments on commit a7d5c59

Please sign in to comment.