Created
January 31, 2016 21:29
-
-
Save Cougar/900e2611507bef55da12 to your computer and use it in GitHub Desktop.
Add run_now() method to tornado.ioloop.PeriodicCallback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.ioloop | |
class PeriodicCallback(tornado.ioloop.PeriodicCallback): | |
def run_now(self): | |
self.stop() | |
self._running = True | |
try: | |
return self.callback() | |
except Exception: | |
self.io_loop.handle_callback_exception(self.callback) | |
finally: | |
self.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.ioloop | |
from periodiccallback import PeriodicCallback | |
import time | |
def cb(): | |
print("CB called at ", time.ctime()) | |
def cb2(): | |
print("call PeriodicCallback immediately") | |
pc.run_now() | |
pc = PeriodicCallback(cb, 3000) | |
pc.start() # run CB every 3 sec | |
PeriodicCallback(cb2, 10000).start() # run it immediately every 10 sec | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment