Skip to content

Commit cbe72d8

Browse files
pierreglaservstinner
authored andcommitted
bpo-36867: _test_multiprocessing: avoid weak sync primitive (GH-13292)
Avoid weak sync primitive in multiprocessing resource_tracker test.
1 parent 3ea702e commit cbe72d8

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3945,11 +3945,19 @@ def test_shared_memory_cleaned_after_process_termination(self):
39453945
# segment should not leak the given memory segment.
39463946
p.terminate()
39473947
p.wait()
3948-
time.sleep(1.0) # wait for the OS to collect the segment
39493948

3950-
# The shared memory file was deleted.
3951-
with self.assertRaises(FileNotFoundError):
3952-
smm = shared_memory.SharedMemory(name, create=False)
3949+
deadline = time.monotonic() + 60
3950+
t = 0.1
3951+
while time.monotonic() < deadline:
3952+
time.sleep(t)
3953+
t = min(t*2, 5)
3954+
try:
3955+
smm = shared_memory.SharedMemory(name, create=False)
3956+
except FileNotFoundError:
3957+
break
3958+
else:
3959+
raise AssertionError("A SharedMemory segment was leaked after"
3960+
" a process was abruptly terminated.")
39533961

39543962
if os.name == 'posix':
39553963
# A warning was emitted by the subprocess' own

0 commit comments

Comments
 (0)