Skip to content

Commit 096ae33

Browse files
authored
bpo-31234: Try to fix lock_tests warning (#3557)
Try to fix the "Warning -- threading_cleanup() failed to cleanup 1 threads" warning in test.lock_tests: wait a little bit longer to give time to the threads to complete. Warning seen on test_thread and test_importlib.
1 parent 65bc620 commit 096ae33

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Lib/test/lock_tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ def wait_for_started(self):
5454
def wait_for_finished(self):
5555
while len(self.finished) < self.n:
5656
_wait()
57+
# Wait a little bit longer to prevent the "threading_cleanup()
58+
# failed to cleanup X threads" warning. The loop above is a weak
59+
# synchronization. At the C level, t_bootstrap() can still be
60+
# running and so _thread.count() still accounts the "almost dead"
61+
# thead.
62+
for _ in range(self.n):
63+
_wait()
5764

5865
def do_finish(self):
5966
self._can_exit = True
@@ -304,6 +311,7 @@ def f():
304311
self.assertRaises(RuntimeError, lock.release)
305312
finally:
306313
b.do_finish()
314+
b.wait_for_finished()
307315

308316
def test__is_owned(self):
309317
lock = self.locktype()

0 commit comments

Comments
 (0)