[Python-ideas] Async API

Yury Selivanov yselivanov.ml at gmail.com
Mon Oct 29 17:42:44 CET 2012


On 2012-10-29, at 1:05 AM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:

> Yury Selivanov wrote:
> 
>>    def coro1():
>>        try:
>>            with timeout(1.0):
>>                yield from coro2() # 1
>>        finally:
>>            try:
>>                with timeout(1.0):
>>                    yield from coro2() # 2
>>            except TimeoutError:
>>                pass
>>    def coro2():
>>        try:
>>            block()
>>            yield # 3
>>            action()
>>        finally:
>>            block()
>>            yield # 4
>>            another_action()
>> Now, if "coro2" is suspended at #4 -- it shouldn't be interrupted with
>> TimeoutError.
>> If, however, "coro2" is at #3 -- it can be, and it doesn't matter was it called from #1 or #2.
> 
> What is your reasoning behind asserting this? Because it's inside
> a try block of its own? Because it's subject to a nested timeout?
> Something else?

Because scheduler, when it is deciding to interrupt a coroutine or not, 
should only question whether that particular coroutine is in its finally, 
and not the one which called it.

-
Yury


More information about the Python-ideas mailing list