Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2019,13 +2019,20 @@ def threading_cleanup(*original_values):
if not _thread:
return
_MAX_COUNT = 100
t0 = time.monotonic()
for count in range(_MAX_COUNT):
values = _thread._count(), threading._dangling
if values == original_values:
break
time.sleep(0.01)
gc_collect()
# XXX print a warning in case of failure?
else:
dt = time.monotonic() - t0
print("Warning -- threading_cleanup() failed to cleanup %s threads "
"after %.0f sec (count: %s, dangling: %s)"
% (values[0] - original_values[0], dt,
values[0], len(values[1])),
file=sys.stderr)

def reap_threads(func):
"""Use this function when threads are being used. This will
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_urllib2_localnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ def setUpModule():

def tearDownModule():
if threads_key:
support.threading_cleanup(threads_key)
support.threading_cleanup(*threads_key)

if __name__ == "__main__":
unittest.main()