Is it possible to do something similar to gnome glib's GSource in asyncio?

Vitaly Krug vitaly.krug at gmail.com
Sun Mar 18 12:26:23 EDT 2018


Mea culpa! It sounds like I should be able to create a specialized future
to test for my loop exit condition and then use that future with asyncio
loop's `run_until_complete()` method.

On Sat, Mar 17, 2018 at 7:39 PM, Vitaly Krug <vitaly.krug at gmail.com> wrote:

> I am looking for a way to get a callback each time before asyncio event
> loop goes back to waiting on I/O (select, epoll, etc.). Documentation and
> googling for the answer hasn't helped yet. I am looking for something
> similar to gnome glib's GSource interface  (https://developer.gnome.org/
> glib/stable/glib-The-Main-Event-Loop.html#GSource).
>
> Here is my use case:
>
> Sometimes it's necessary to wrap an asynchronous implementation in a
> synchronous API. This is how Pika AMQP client's BlockingConnection adapter
> is built on top of Pika's asynchronous SelectConnection adapter without
> incurring the overhead of multi-threading.
>
> The blocking wrapper makes calls into the asynchronous layer and runs the
> event loop (pika's proprietary select/epoll/kqueue event loop) while
> waiting for the asynchronous request to complete.
>
> For no-reply (i.e., no-ack) type of requests, the blocking wrapper simply
> waits for the write buffers to empty out before returning - for this, it
> checks the size of the write buffer each time before event loop goes back
> to waiting for I/O on select/epoll/kqueue. And if the blocking layer finds
> that the write buffer has emptied, it stops the event loop, so control can
> return to the user of the blocking interface.
>
> So, I need to be able to do something similar in asyncio to facilitate
> rebasing BlockingConnection on asyncio in Python3.
>
> Thank you in advance.
>
> Vitaly
>
>
>
>



More information about the Python-list mailing list