[Python-ideas] Async API

Steve Dower Steve.Dower at microsoft.com
Thu Oct 25 17:28:29 CEST 2012


>>> Mine is a quick hack to add 'gi_in_finally' property
>>> to generators and see how good/bad it is.
>>
>> I feel it's a code smell if you need to use this feature a lot. If you
>> need it rarely, well, use one of the existing work-arounds.
>But the feature isn't going to be used by users directly.  It will be used
>only in scheduler implementations.  Users will just write 'finally' blocks
>and they will work as expected. This just makes coroutines look and behave
>more like ordinary functions.  Isn't it one of our goals--to make it
>convenient and reliable?

I'm agree with the intent, but I'm more worried about the broadness of this approach. What happens in this case?

try:
    try:
        yield some_op()
    finally:
        yield cleanup_that_raises_network_error()
except NetworkError:
    # will we ever see this?

Basically, I don't think we can handle the "don't raise" cases entirely automatically, though I'd like to be able to.

Cheers,
Steve


More information about the Python-ideas mailing list