Search code examples
pythontornado

Adding PeriodicCallback to already running IOLoop instance


I want to create a simple scheduler in Tornado, where along the course of the app, some job with a (time,callback) is generated dynamically, for example,

Send a push notification 30 mins before an event, but this reminder is created only after the job is created by the server, which may be through a POST request.

I wanted to achieve this through PeriodicCallback, but I read that IOLoop.start() must be called after the PeriodicCallback is created. How can I add PeriodicCallback to already running IOLoop or is there any other way?


Solution

  • There is no requirement that PeriodicCallbacks be started before the IOLoop. You can start them while the IOLoop is running. You have to schedule something before calling IOLoop.start() since that will run forever, but whatever you schedule on the IOLoop can go on to schedule other stuff.