[Python-ideas] PEP 525: Asynchronous Generators
Stefan Behnel
stefan_ml at behnel.de
Sat Aug 6 13:03:30 EDT 2016
Yury Selivanov schrieb am 06.08.2016 um 18:39:
> You can implement async generators using async iteration protocol as
> it was defined in PEP 492.
> [...]
> Essentially, because pure Python async generators work fine
> with 'async for' and will continue to do so in 3.6, I think
> there shouldn't be technical problems to add asynchronous
> generators in Cython.
Hmm, I thought that at least interoperability might get in the way. I guess
I'll just have to give it a try...
> 2. It's extremely unlikely that somebody will design a system that
> switches coroutine runners *while async/awaiting a coroutine*.
Yes, I guess so.
> But even in this unlikely use case, you can
> easily stack finalizers following this pattern:
>
> old_finalizer = sys.get_asyncgen_finalizer()
> sys.set_asyncgen_finalizer(my_finalizer)
> try:
> # do my thing
> finally:
> sys.set_asyncgen_finalizer(old_finalizer)
That only works for synchronous code, though, because if this is done in a
coroutine, it might get suspended within the try block and would leak its
own finalizer into the outer world.
Stefan
More information about the Python-ideas
mailing list