mirror of
https://github.com/python/cpython.git
synced 2025-11-02 11:08:57 +00:00
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
This commit is contained in:
parent
b85c136903
commit
d20324a7fa
2 changed files with 9 additions and 2 deletions
|
|
@ -2019,13 +2019,20 @@ def threading_cleanup(*original_values):
|
||||||
if not _thread:
|
if not _thread:
|
||||||
return
|
return
|
||||||
_MAX_COUNT = 100
|
_MAX_COUNT = 100
|
||||||
|
t0 = time.monotonic()
|
||||||
for count in range(_MAX_COUNT):
|
for count in range(_MAX_COUNT):
|
||||||
values = _thread._count(), threading._dangling
|
values = _thread._count(), threading._dangling
|
||||||
if values == original_values:
|
if values == original_values:
|
||||||
break
|
break
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
gc_collect()
|
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):
|
def reap_threads(func):
|
||||||
"""Use this function when threads are being used. This will
|
"""Use this function when threads are being used. This will
|
||||||
|
|
|
||||||
|
|
@ -664,7 +664,7 @@ def setUpModule():
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
if threads_key:
|
if threads_key:
|
||||||
support.threading_cleanup(threads_key)
|
support.threading_cleanup(*threads_key)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue