[Python-ideas] PEP 3156 EventLoop: hide details of iterations and idleness?

Ben Darnell ben at bendarnell.com
Tue Jan 22 16:31:22 CET 2013


On Tue, Jan 22, 2013 at 3:04 AM, Geert Jansen <geertj at gmail.com> wrote:
> - call_every_iteration() vs call_repeatedly(): you really need both. I
> did a small proof of concept to integrate libdbus with the tulip event
> loop. I use call_every_iteration() to dispatch events every time after
> IO has happened. The idea is that events will always originate from
> IO, and therefore having a callback on every iteration is a convenient
> way to check for events that need to be dispatched. Using
> call_repeatedly() here is not right, because there may be times that
> there are 100s of events per second, and times there are none. There
> is no sensible fixed polling frequency.
>
I don't understand what you mean by "events will always originate from IO"
(I don't know anything about libdbus). If the events are coming from IO
that causes an event loop iteration, it must be from some tulip callback.
 Why can't that callback be responsible for scheduling any further
dispatching that may be needed?
>> If Tornado doesn't have infrastructure for call_every_iteration() you
> could emulate it with a function that re-reschedules itself using
> call_soon() just before calling the callback. (See my first point
> about when call_soon() callbacks are scheduled.)
>
No, because call_soon (and call_later(0)) cause the event loop to use a
timeout of zero on its next poll call, so a function that reschedules
itself with call_soon will be a busy loop. There is no good way to emulate
call_every_iteration from the other methods; you'll either busy loop with
call_soon or use a fixed timeout. If you need it it's an easy thing to
offer, but since neither tornado nor twisted have such a method I'm
questioning the need.
run_once() will run for an unpredictable amount of time (until the next IO
or timeout); run_forever() with call_soon(stop) will handle events that are
ready at that moment and then stop.
-Ben
>> If you want to see how event loop adapters for libev and libuv look
> like, you can check out my project here:
> https://github.com/geertj/looping
>> Regards,
> Geert
>-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130122/54b0d66c/attachment.html>


More information about the Python-ideas mailing list

AltStyle によって変換されたページ (->オリジナル) /