[Python-ideas] The async API of the future
Jasper St. Pierre
jstpierre at mecheye.net
Sat Oct 20 05:20:22 CEST 2012
On Fri, Oct 19, 2012 at 11:11 PM, Greg Ewing
<greg.ewing at canterbury.ac.nz> wrote:
> Jasper St. Pierre wrote:
>>
>> For most windowing systems, this isn't true. You need to call some
>> function to check if you have events pending. For X11, this is
>> "XPending". For Win32, this is "GetQueueStatus".
>
>
> X11 is ultimately reading its events from the socket to
> the display server. If you select() that socket, it will
> tell you whenever the X11 event loop could possibly have
> something to do.
Nope. libX11/XCB keep their own queue of events and do their own
socket management, so it's not just "poll on this FD, thanks"
http://cgit.freedesktop.org/xorg/lib/libX11/tree/src/Pending.c
http://cgit.freedesktop.org/xorg/lib/libX11/tree/src/xcb_io.c#n344
> On Windows, I imagine the equivalent would be to pass your
> message queue handle to a WaitForMultipleObjects call.
> I've never tried to do anything like that, though, so
> I don't know if it would really work.
>
>
>> What Twisted does is this case is swap out their own select
>> loop with another implementation built around GLib's GMainLoop,
>
>
> If it's truly impossible to incorporate GMainLoop as a
> sub-loop of something else, then this is a bad situation.
> What happens if you also want to use some other library
> that insists on *its* main loop being in charge? This
> cannot be a general solution.
GLib has a way of embedding its main loop in another, but it's not
easy or viable to use in a situation like this. It basically splits up
its event loop into multiple pieces (prepare, check, dispatch), which
you call at various times. Qt uses this for their GLib mainloop
integration.
It's clear there's never going to be one event loop solution (as Guido
already mentioned, there's wars about libuv/libevent/libev that we
can't possibly resolve), so why pretend like there is?
> --
> Greg
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
--
Jasper
More information about the Python-ideas
mailing list