Last active
October 14, 2015 09:35
-
-
Save squeaky-pl/67850b7371cfe8f3aa6b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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