[Async-sig] Asynchronous cleanup is a problem
Yury Selivanov
yselivanov at gmail.com
Wed Jul 6 21:08:31 EDT 2016
> On Jul 6, 2016, at 8:47 PM, Glyph Lefkowitz <glyph at twistedmatrix.com> wrote:
>
>
>> On Jul 6, 2016, at 5:25 PM, Yury Selivanov <yselivanov at gmail.com> wrote:
>>
>> The problem is that the GC can’t execute async code, and we don’t have any control over GC. What if we add a mechanism to control how async generators (AG) are destructed. Let’s say we add new function to the sys module - `sys.set_async_generator_finalizer(finalizer)`. We already have sys.set_coroutine_wrapper(), so this isn’t something unprecedented.
>
> There isn't just one event loop though, and what trampoline to attach a dying coroutine to depends heavily on what event loop it came from. It seems like a single global value for this in 'sys' would just be ... wrong.
But there can only be one currently running event loop per thread...
Another way is to add sys.set_async_generator_wrapper() (and a getter, so that loops can maintain a stack of them). With it a running event loop can create a weak ref to a generator that is created in a coroutine that the loop is currently running. And with a weakref it can later finalize the generator.
Yury
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/async-sig/attachments/20160706/5a8d2af2/attachment.html>
More information about the Async-sig
mailing list