Skip to content

Instantly share code, notes, and snippets.

@justinmoon
Created August 14, 2018 19:32
Show Gist options
  • Save justinmoon/2ca180f4a6a2e4940502b7fc0a3cad93 to your computer and use it in GitHub Desktop.
Save justinmoon/2ca180f4a6a2e4940502b7fc0a3cad93 to your computer and use it in GitHub Desktop.
Check if thread is dead in Python
import threading
import time
def doom():
raise RuntimeError()
def zoom():
while True:
time.sleep(1)
doomed = threading.Thread(target=doom, name="doomed")
doomed.start()
zoomed = threading.Thread(target=zoom, name="zoomed")
zoomed.start()
time.sleep(1)
print(f"Is {doomed.name} alive? {doomed.is_alive()}")
print(f"Is {zoomed.name} alive? {zoomed.is_alive()}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment