(original) (raw)
On Tue, Jan 22, 2013 at 3:04 AM, Geert Jansen <geertj@gmail.com> wrote:
- call\_every\_iteration() vs call\_repeatedly(): you really need both. Idid 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