Skip to content

Commit

Permalink
pythongh-111644: Enhance support threading_cleanup()
Browse files Browse the repository at this point in the history
Copy the list of dangling thread to provide a consistent output
between the warning and the "Dangling thread" listing.
  • Loading branch information
vstinner committed Nov 3, 2023
1 parent f21b230 commit 20c4268
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Lib/test/support/threading_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,22 @@ def threading_cleanup(*original_values):
if not count:
# Display a warning at the first iteration
support.environment_altered = True
dangling_threads = values[1]

# Copy the thread list to get a consistent output between the
# warning and the "Dangling thread" listing.
dangling_threads = list(values[1])

support.print_warning(f"threading_cleanup() failed to cleanup "
f"{values[0] - original_values[0]} threads "
f"(count: {values[0]}, "
f"dangling: {len(dangling_threads)})")
for thread in dangling_threads:
support.print_warning(f"Dangling thread: {thread!r}")

# Don't hold references to threads
# Break any potential reference cycle
dangling_threads = None

# Break any potential reference cycle
values = None

time.sleep(0.01)
Expand Down

0 comments on commit 20c4268

Please sign in to comment.