Created
January 13, 2026 11:16
-
-
Save josepsmartinez/6b640ec0e32b27117d63b5b47622febd to your computer and use it in GitHub Desktop.
Python threading debug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import threading | |
| import traceback | |
| def check_alive_threads(): | |
| print(f"\n--- Active Threads: {threading.active_count()} ---") | |
| for thread in threading.enumerate(): | |
| print(f"Name: {thread.name}") | |
| print(f" ID: {thread.ident}") | |
| print(f" Daemon: {thread.daemon}") | |
| print(f" Is Alive: {thread.is_alive()}") | |
| print("-" * 30) | |
| ... | |
| # End of program | |
| check_alive_threads() | |
| # Get the stack frame for the MainThread | |
| main_thread_id = threading.main_thread().ident | |
| frame = sys._current_frames().get(main_thread_id) | |
| if frame: | |
| print("\n--- MainThread is currently here: ---") | |
| traceback.print_stack(frame) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment