From: Ben Darnell Date: Tue, 4 Oct 2011 15:54:38 +0000 (-0700) Subject: Always advance _next_timeout in PeriodicCallback._schedule_next(). X-Git-Tag: v2.1.1~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c5e19a045d91b04c2796154a86b945adb784554e;p=thirdparty%2Ftornado.git Always advance _next_timeout in PeriodicCallback._schedule_next(). On fast machines (and platforms where time.time() has low resolution), it's possible to make it through an IOLoop iteration with time.time() unchanged, which would cause the callback to be run multiple times regardless of the requested interval. Closes #366. --- diff --git a/tornado/ioloop.py b/tornado/ioloop.py index f9a9f372e..bcf5d521c 100644 --- a/tornado/ioloop.py +++ b/tornado/ioloop.py @@ -477,7 +477,7 @@ class PeriodicCallback(object): def _schedule_next(self): if self._running: current_time = time.time() - while self._next_timeout < current_time: + while self._next_timeout <= current_time: self._next_timeout += self.callback_time / 1000.0 self.io_loop.add_timeout(self._next_timeout, self._run)