Skip to content
Open
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: 9 additions & 0 deletions easypy/threadtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ def wrapper(*args, **kwargs):
try:
return target(*args, **kwargs)
finally:
# remove the snapshot connecting parent → this thread
_FRAME_SNAPSHOTS_REGISTRY.pop((parent_thread.uuid, thread.uuid), None)

# if this thread can also be a parent for other children later,
# remove any snapshots where it is the parent
to_delete = [key for key in _FRAME_SNAPSHOTS_REGISTRY if key[0] == thread.uuid]
for key in to_delete:
_FRAME_SNAPSHOTS_REGISTRY.pop(key, None)

IDENT_TO_UUID.pop(thread.ident)

return _orig_start_new_thread(wrapper, *args, **kwargs)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_threadtree.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import threading

from easypy.threadtree import walk_frames
from easypy.threadtree import walk_frames, _FRAME_SNAPSHOTS_REGISTRY


def collect_frames():
Expand Down Expand Up @@ -53,3 +53,4 @@ def func_a():
]
actual = [frame.f_code.co_name for frame in frames]
assert actual == expected
assert len(_FRAME_SNAPSHOTS_REGISTRY) == 0, "Frame snapshots registry should be empty after threads have finished"