alternate approach to timer inaccuracy due to cached times

Brandon Black blblack at
Fri Oct 14 06:19:58 CEST 2011

On Thu, Oct 13, 2011 at 9:08 PM, Shaun Lindsay <srlindsay at> wrote:
> I think my description of the issue was lacking.  This is not specific to
> gevent.  To illustrate the problem, I've included a C test program that
> reproduces the timeout problems [...]

libev's way of doing things (using loop start time) is just more
efficient for most normal cases, because normally you don't have large
delays/blocks in your callbacks in an event-driven program.  In the
big picture, it sounds like the primary issue in your original code is
that you're doing blocking database calls in the midst of an event
callback.  That's going to screw up a lot of assumptions right there.
Usually the way to handle this (assuming the database driver can't be
hooked into the loop the way things should be) is to spawn a
thread/process to handle SQL stuff asynchronously and talk to it over
a local socketpair.

If you're really stuck with this though, you could also switch to
ev.pod's 4th strategy for timers, where all of your socket error
timeouts are collapsed into one timeout watcher and go from there on
the loop time issues.

More information about the libev mailing list