[Python-ideas] Async API
Sam Rushing
sam-pydeas at rushing.nightmare.com
Wed Oct 24 02:24:54 CEST 2012
On 10/23/12 4:30 PM, Yury Selivanov wrote:
>
> How do you protect finally statements in shrapnel? If we have a following
> coroutine (greenlet style):
>
> def foo():
> connection = open_connection()
> try:
> spam()
> finally:
> [some code]
> connection.close()
>
> What happens if you run 'foo.with_timeout(1)' and timeout occurs at
> "[some code]" point? Will you just abort 'foo', possibly preventing
> 'connection' from being closed?
>
Timeouts are raised as normal exceptions - for exactly this reason.
The interesting part of the implementation is keeping each
with_timeout() call separate.
If you have nested with_timeout() calls and the outer timeout goes off,
it will skip the inner exception handler and fire only the outer one.
In other words, the code for with_timeout() verifies that any timeouts
propagating through it belong to it.
https://github.com/ironport/shrapnel/blob/master/coro/_coro.pyx#L1126-1142
-Sam
More information about the Python-ideas
mailing list