Skip to content

Commit d20324a

Browse files
authored
support.threading_cleanup() log a warning on fail (#1195)
The @reap_threads decorator and the threading_cleanup() function of test.support now log a warning if they fail to clenaup threads. Fix also the usage of support.threading_cleanup() in test_urllib2_localnet. The log may help to debug such other warning seen on the AMD64 FreeBSD CURRENT Non-Debug 3.x buildbot: Warning -- threading._dangling was modified by test_logging
1 parent b85c136 commit d20324a

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

Lib/test/support/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2019,13 +2019,20 @@ def threading_cleanup(*original_values):
20192019
if not _thread:
20202020
return
20212021
_MAX_COUNT = 100
2022+
t0 = time.monotonic()
20222023
for count in range(_MAX_COUNT):
20232024
values = _thread._count(), threading._dangling
20242025
if values == original_values:
20252026
break
20262027
time.sleep(0.01)
20272028
gc_collect()
2028-
# XXX print a warning in case of failure?
2029+
else:
2030+
dt = time.monotonic() - t0
2031+
print("Warning -- threading_cleanup() failed to cleanup %s threads "
2032+
"after %.0f sec (count: %s, dangling: %s)"
2033+
% (values[0] - original_values[0], dt,
2034+
values[0], len(values[1])),
2035+
file=sys.stderr)
20292036

20302037
def reap_threads(func):
20312038
"""Use this function when threads are being used. This will

Lib/test/test_urllib2_localnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ def setUpModule():
664664

665665
def tearDownModule():
666666
if threads_key:
667-
support.threading_cleanup(threads_key)
667+
support.threading_cleanup(*threads_key)
668668

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

0 commit comments

Comments
 (0)