Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4333aff

Browse files
committed
Try to fix sporadic failure in test_thread/test_threading
2 parents e886047 + 45fdb45 commit 4333aff

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Lib/test/lock_tests.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,13 @@ def f():
149149
# We run many threads in the hope that existing threads ids won't
150150
# be recycled.
151151
Bunch(f, 15).wait_for_finished()
152-
self.assertEqual(n, len(threading.enumerate()))
152+
if len(threading.enumerate()) != n:
153+
# There is a small window during which a Thread instance's
154+
# target function has finished running, but the Thread is still
155+
# alive and registered. Avoid spurious failures by waiting a
156+
# bit more (seen on a buildbot).
157+
time.sleep(0.4)
158+
self.assertEqual(n, len(threading.enumerate()))
153159

154160
def test_timeout(self):
155161
lock = self.locktype()

0 commit comments

Comments
 (0)