Created
August 14, 2018 19:32
-
-
Save justinmoon/2ca180f4a6a2e4940502b7fc0a3cad93 to your computer and use it in GitHub Desktop.
Check if thread is dead in Python
This file contains 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 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