I think the cleanest way would be to catch the exception you consider fatal and do sys.exit() (you'll need gevent 1.0 since before that SystemExit did not exit the process).
Another way is to use link_exception, which would be called if the greenlet died with an exception.
spawn(important_greenlet).link_exception(lambda *args: sys.exit("important_greenlet died"))
Note, that you also need gevent 1.0 for this to work.
If on 0.13.6, do something like this to kill the process:
gevent.get_hub().parent.throw(SystemExit())
edited Feb 9 '12 at 10:30
|
Hello,When a greenlet raises an exception which isn't handled, gevent prints the traceback but other greenlets keep running. This could potentially leave my application in a weird failure state, so I rather prefer the entire process to terminate instead of only the failed greenlet.At the moment, I'm using the following code to achieve this:gevent.get_hub().SYSTEM_ERROR = (BaseException, )
However, this causes two tracebacks to be printed: once for the greenlet (with a correct traceback), once for the main code (with an irrelevant traceback, from the hub).This approach also has the problem of treating GreenletExit and SystemExit as a system error.I could suppress the second traceback, but this would hide exceptions that don't originate from inside a greenlet.What's the proper way to terminate the process when a greenlet doesn't handle an exception?
Thanks!--
You received this message because you are subscribed to the Google Groups "gevent: coroutine-based Python network library" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gevent+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.