Last active
June 26, 2019 07:48
-
-
Save xmonader/517b6818a0a36a2fab1344ce721d0a4c to your computer and use it in GitHub Desktop.
gevent link exception and value
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 as g | |
| from functools import partial | |
| import traceback | |
| def fn(*args, **kwargs): | |
| print("ARGS: ", args) | |
| print("KWARGS: ", kwargs) | |
| g.sleep(3) | |
| return 150 | |
| def fnWithException(*args, **kwargs): | |
| print("ARGS: ", args) | |
| print("KWARGS: ", kwargs) | |
| g.sleep(3) | |
| raise ValueError | |
| def on_error(fut): | |
| print("something happened.") | |
| try: | |
| fut.get() | |
| except Exception as e: | |
| print("ERROR HAPPEEND: ", str(e) + traceback.format_exc()) | |
| def on_value(fut): | |
| print("SUCCESS: ", fut.value) | |
| if __name__ == "__main__": | |
| args1 = ["job1", "5", "6"] | |
| f1 = g.spawn(fn, args1) | |
| f1.link_exception(on_error) | |
| f1.link_value(on_value) | |
| args2 = ["job2", "7", "11"] | |
| f2 = g.spawn(fnWithException, *args2) | |
| f2.link_exception(on_error) | |
| f2.link_value(on_value) | |
| g.joinall([f1,f2], raise_error=False) | |
| print("here...") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment