[Python-ideas] PEP 3156 EventLoop: hide details of iterations and idleness? (original) (raw)
Ben Darnell ben at bendarnell.com
Tue Jan 22 16:31:22 CET 2013
- Previous message: [Python-ideas] PEP 3156 EventLoop: hide details of iterations and idleness?
- Next message: [Python-ideas] PEP 3156 EventLoop: hide details of iterations and idleness?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, Jan 22, 2013 at 3:04 AM, Geert Jansen <geertj at gmail.com> wrote:
- calleveryiteration() vs callrepeatedly(): you really need both. I did a small proof of concept to integrate libdbus with the tulip event loop. I use calleveryiteration() 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 callrepeatedly() 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 calleveryiteration() you could emulate it with a function that re-reschedules itself using callsoon() just before calling the callback. (See my first point about when callsoon() 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>
- Previous message: [Python-ideas] PEP 3156 EventLoop: hide details of iterations and idleness?
- Next message: [Python-ideas] PEP 3156 EventLoop: hide details of iterations and idleness?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]