Write scheduler inside tornado

2,495 views
Skip to first unread message

Grigory Fateyev

unread,
Apr 14, 2010, 10:06:43 AM4/14/10
to Tornado server
Hello!

I need to run function with an interval of 10 minutes. What is the
best way to do that?

--
Всего наилучшего!

Otávio Souza

unread,
Apr 14, 2010, 10:26:07 AM4/14/10
to python-...@googlegroups.com
IOLoop.add_timeout
 """Calls the given callback at the time deadline from the I/O loop."""
2010/4/14 Grigory Fateyev <gfb...@gmail.com>


--
To unsubscribe, reply using "remove me" as the subject.



--
Otávio Souza
* KinuX Linux Creator <http://kinuxlinux.org>
* Participante Linux-SE
* Criador dos lunatiKos (Grupo de usuários KDE do Nordeste)
* Linux User #415774

ken248000

unread,
Apr 14, 2010, 10:26:12 AM4/14/10
to python-...@googlegroups.com
a cronjob??

2010/4/14 Grigory Fateyev <gfb...@gmail.com>:

Season Lee

unread,
Apr 14, 2010, 10:58:05 AM4/14/10
to python-...@googlegroups.com
You can use tornado.ioloop.PeriodicCallback to create a period timer.
Of course you can call IOLoop.add_timeout to create a timeout callback.Note that the timer created by IOLoop.add_timeout will run only once.
 
Maybe the code bellow will do you a favour:
 
def callback():
    print "DO SOMETHING HERE"
 
#milliseconds
interval_ms = 10 * 60 * 1000
main_loop = tornado.ioloop.IOLoop.instance()
scheduler = tornado.ioloop.PeriodicCallback(callback,interval_ms, io_loop = main_loop)
#start your period timer
scheduler.start()
#start your loop
main_loop.start()

 
2010/4/14 Grigory Fateyev <gfb...@gmail.com>

Grigory Fateyev

unread,
Apr 14, 2010, 12:23:40 PM4/14/10
to python-...@googlegroups.com
Hello Otávio Souza!

On Wed, 14 Apr 2010 11:26:07 -0300 you wrote:

> IOLoop.add_timeout
> """Calls the given callback at the time deadline from the I/O

Otavio, thank you. Can you give me a small example how to use this
method?

Otávio Souza

unread,
Apr 14, 2010, 1:07:16 PM4/14/10
to python-...@googlegroups.com
Hello there Grigory, I think Season Lee gave an smart example =)

But using the add_timeout method, as explained, call only once, the simple code is that one:

from tornado.ioloop import time

def call_me():
     print("Something")

tornado.ioloop.IOLoop.instance().add_timeout(time.time()+(10*60),call_me);
tornado.ioloop.IOLoop.instance().start();

2010/4/14 Grigory Fateyev <gfb...@gmail.com>
--
To unsubscribe, reply using "remove me" as the subject.

Grigory Fateyev

unread,
Apr 14, 2010, 1:55:38 PM4/14/10
to python-...@googlegroups.com
Hello Season Lee!

On Wed, 14 Apr 2010 22:58:05 +0800 you wrote:

> You can use tornado.ioloop.PeriodicCallback to create a period timer.
> Of course you can call IOLoop.add_timeout to create a timeout
> callback.Note that the timer created by IOLoop.add_timeout will run
> only once.
>
> Maybe the code bellow will do you a favour:
>
> def callback():
> print "DO SOMETHING HERE"
>
> #milliseconds
> interval_ms = 10 * 60 * 1000
> main_loop = tornado.ioloop.IOLoop.instance()
> scheduler = tornado.ioloop.PeriodicCallback(callback,interval_ms,
> io_loop = main_loop)
> #start your period timer
> scheduler.start()
> #start your loop
> main_loop.start()

Season, thank you very much for that complex example!

Also, thanks to Otavio and Ken.

Reply all
Reply to author
Forward
0 new messages