MCPcopy Index your code
hub / github.com/RustPython/RustPython / threading_cleanup

Function threading_cleanup

Lib/test/support/threading_helper.py:27–54  ·  view source on GitHub ↗
(*original_values)

Source from the content-addressed store, hash-verified

25
26
27def threading_cleanup(*original_values):
28 orig_count, orig_ndangling = original_values
29
30 timeout = 1.0
31 for _ in support.sleeping_retry(timeout, error=False):
32 # Copy the thread list to get a consistent output. threading._dangling
33 # is a WeakSet, its value changes when it's read.
34 dangling_threads = list(threading._dangling)
35 count = _thread._count()
36
37 if count <= orig_count:
38 return
39
40 # Timeout!
41 support.environment_altered = True
42 support.print_warning(
43 f"threading_cleanup() failed to clean up threads "
44 f"in {timeout:.1f} seconds\n"
45 f" before: thread count={orig_count}, dangling={orig_ndangling}\n"
46 f" after: thread count={count}, dangling={len(dangling_threads)}")
47 for thread in dangling_threads:
48 support.print_warning(f"Dangling thread: {thread!r}")
49
50 # The warning happens when a test spawns threads and some of these threads
51 # are still running after the test completes. To fix this warning, join
52 # threads explicitly to wait until they complete.
53 #
54 # To make the warning more likely, reduce the timeout.
55
56
57def reap_threads(func):

Callers 1

decoratorFunction · 0.85

Calls 3

listClass · 0.85
lenFunction · 0.85
_countMethod · 0.45

Tested by

no test coverage detected