tornado.ioloop.IOLoop.current().time() gives Zulu. How do I get my time regarding timezone to add some seconds as deadline in IOLoop.add_timeout(deadline) so timeout triggers in future correctly?
My time is +1h and it does not trigger because the 60s i IOLoop.add_timeout(60) are already passed. But during summer I have +2h so I have to add my timezone-offset correctly during summer and wintertime...
Fortunately that isn't timezone-related problem. What confused you is probably deadline vs delay terminology. Thankfully the IOLoop.add_timeout
's documentation is pretty clear,
deadline may be a number denoting a time (on the same scale as IOLoop.time, normally time.time), or a datetime.timedelta object for a deadline relative to the current time. Since Tornado 4.0, call_later is a more convenient alternative for the relative case since it does not require a timedelta object.
A code like:
IOLoop.current().add_timeout(60, some_func)
actually means to run a function 60 seconds after unix epoch (00:00:00 UTC on 1 January 1970) not from now (time.time()
). so it riggers immediately.
As docs states, you may either
pass delay as a timedelta object
import datetime
IOLoop.current().add_timeout(datetime.timedelta(seconds=60), some_func)
or use IOloop.call_Later()
IOLoop.current().call_later(delay=60, some_func)