Skip to content

Instantly share code, notes, and snippets.

@squeaky-pl
Last active October 14, 2015 09:35
Show Gist options
  • Save squeaky-pl/67850b7371cfe8f3aa6b to your computer and use it in GitHub Desktop.
Save squeaky-pl/67850b7371cfe8f3aa6b to your computer and use it in GitHub Desktop.
import gevent
def green_thread(timeout, explode):
counter = 1
while 1:
gevent.sleep(timeout)
print(timeout)
counter += 1
if counter % explode == 0:
1 / 0
if __name__ == '__main__':
threads = {}
def make_thread(key, args):
def on_exception(thread):
print('Boom!')
make_thread(key, args)
thread = gevent.spawn(green_thread, *args)
thread.link_exception(on_exception)
threads[key] = thread
make_thread('five', [5, 2])
make_thread('three', [3, 3])
gevent.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment