Most idiomatic way of handling "asynchronous exceptions"?

60 views
Skip to first unread message

Ian Shefferman

unread,
Oct 8, 2015, 5:25:38 PM10/8/15
to gevent: coroutine-based Python network library
I am running gevent 1.1 beta.

Given the following:

- A "parent", which may or may not be in its own greenlet
- A constantly running "child" greenlet spawned by the parent which sends a keepalive request to a server at a set interval. This greenlet is never join()'d or get()'d.

I'd like to be able to raise an exception in the parent when the child receives an exception from the server. I'd ideally like to do this as soon as the child receives the error, rather than setting and checking a sentinel variable to determine if the keepalive heartbeat is healthy or not before every single function/method call.

I also saw some examples with calling link_exception with a callable that runs sys.exit(), but I don't want to kill the whole program. I just want to bubble up the greenlet's exception as soon as it generates one.

My understanding is that pre-1.0 versions of gevent allowed some way of doing this with link_exception/spawn_link_exception, but it was later removed.

What is the most idiomatic way of accomplishing this?

Thanks.
Reply all
Reply to author
Forward
0 new messages