Skip to content

Instantly share code, notes, and snippets.

@CatherineH
Created March 2, 2017 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CatherineH/bbfedca39ec7261e356df108c599d33f to your computer and use it in GitHub Desktop.
Save CatherineH/bbfedca39ec7261e356df108c599d33f to your computer and use it in GitHub Desktop.
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(thread.name + " 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")
t1.start()
t2.start()
t3.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment