From c17e6e45e3d5b18961f59ccccd38ce71eee2cf0a Mon Sep 17 00:00:00 2001 From: Adam Holmberg Date: Wed, 6 May 2015 10:52:04 -0500 Subject: [PATCH] libev: service timeouts before updating loop timer. Also, never start a timer with zero repeat (this causes it to stop, rather than timeout immediately). --- cassandra/io/libevreactor.py | 1 + cassandra/io/libevwrapper.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cassandra/io/libevreactor.py b/cassandra/io/libevreactor.py index 31c9cd38..e6abb76b 100644 --- a/cassandra/io/libevreactor.py +++ b/cassandra/io/libevreactor.py @@ -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: diff --git a/cassandra/io/libevwrapper.c b/cassandra/io/libevwrapper.c index 1c52a964..99e1df30 100644 --- a/cassandra/io/libevwrapper.c +++ b/cassandra/io/libevwrapper.c @@ -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; }