libev: service timeouts before updating loop timer.

Also, never start a timer with zero repeat (this causes it to stop,
rather than timeout immediately).
This commit is contained in:
Adam Holmberg
2015-05-06 10:52:04 -05:00
parent 60f59ce7f2
commit c17e6e45e3
2 changed files with 4 additions and 1 deletions

View File

@@ -148,6 +148,7 @@ class LibevLoop(object):
def _update_timer(self):
if not self._shutdown:
self._timers.service_timeouts()
offset = self._timers.next_offset or 100000 # none pending; will be updated again when something new happens
self._loop_timer.start(offset)
else:

View File

@@ -517,7 +517,9 @@ Timer_start(libevwrapper_Timer *self, PyObject *args) {
if (!PyArg_ParseTuple(args, "d", &timeout)) {
return NULL;
}
self->timer.repeat = fmax(timeout, 0.0);
/* some tiny non-zero number to avoid zero, and
make it run immediately for negative timeouts */
self->timer.repeat = fmax(timeout, 0.000000001);
ev_timer_again(self->loop->loop, &self->timer);
Py_RETURN_NONE;
}