Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
an example of a python script that watches all threads for early termination
from threading import Thread, enumerate
import logging
def fails():
for i in range(999999999):
assert i < 9999999
def succeeds():
while True:
assert 2 == 2
def watcher():
init_threads = enumerate()
while True:
curr_threads = enumerate()
if len(curr_threads) < len(init_threads):
for thread in init_threads:
if thread not in curr_threads:
logging.error( + " not found")
init_threads = curr_threads
if __name__ == "__main__":
t1 = Thread(target=succeeds, name="succeeds")
t2 = Thread(target=fails, name="fails")
t3 = Thread(target=watcher, name="watcher")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.