]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Added period check in PeriodicCallback
authorPeter Sobot <github@petersobot.com>
Tue, 23 Oct 2012 18:33:17 +0000 (15:33 -0300)
committerPeter Sobot <github@petersobot.com>
Tue, 23 Oct 2012 18:33:17 +0000 (15:33 -0300)
If a user currently passes in 0ms (hopefully by accident) as the
callback time for a periodic callback, Tornado consumes a huge amount
of CPU and never calls the function.

tornado/ioloop.py

index 02046d3d164435def76281391a9322943fb572cf..dfbb462b3417e0e2d431c5fe4803b3e170db9f0a 100644 (file)
@@ -679,6 +679,8 @@ class PeriodicCallback(object):
     """
     def __init__(self, callback, callback_time, io_loop=None):
         self.callback = callback
+        if callback_time == 0:
+            raise ValueError("Periodic callback cannot have a period of 0ms")
         self.callback_time = callback_time
         self.io_loop = io_loop or IOLoop.instance()
         self._running = False