Skip to content

Instantly share code, notes, and snippets.

@josepsmartinez
Created January 13, 2026 11:16
Show Gist options
  • Select an option

  • Save josepsmartinez/6b640ec0e32b27117d63b5b47622febd to your computer and use it in GitHub Desktop.

Select an option

Save josepsmartinez/6b640ec0e32b27117d63b5b47622febd to your computer and use it in GitHub Desktop.
Python threading debug
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