Question

In using gevent, whenever a child greenlet throws an exception, I would like it to bubble up to the parent (and ideally have the parent throw the exception). In the documentation for greenlets, it says this is automatically done, but this doesn't appear to be the case in gevent.

How do I bubble up exceptions in gevent?

Thanks!

Was it helpful?

Solution

If you link() the child greenlet to the parent greenlet, then LinkedExited will be raised in the parent when the child exits. At that point you can check the exception property of the child greenlet. It will contain the exception instance raised in the child (if the child finished with an error). Now that you have the exception, you could handle it right away in the parent or you could raise it in the parent.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top