Scheduler
— Scheduler watcher¶
-
class
Scheduler
(reschedule, loop[, callback=None, data=None, priority=0])¶ Parameters: Scheduler
watchers are specialisedPeriodic
watchers. Each time theScheduler
watcher gets scheduled, thereschedule
callback is called with the watcher as first, and the current time as second argument. Example:def myreschedule(watcher, now): return now + 60.0 Scheduler(myreschedule, loop, callback)
This can be used to create very complex timers, such as a timer that triggers on “next midnight, local time”. To do this, you would calculate the next midnight after now and return the timestamp value for this. This cannot be done with
Timer
watchers, as those cannot react to time jumps.-
reset
()¶ Simply stops and restarts the watcher. This is only useful when
reschedule
would return a different time than the last time it was called (e.g. in a crond like program when the crontabs have changed).
-
reschedule
¶ The current reschedule callback, its signature must be:
It must always return a
float
greater than or equal to the now argument to indicate the next time the watchercallback
should be invoked. It will usually be called just before thecallback
is triggered, but might be called at other times, too.Warning
- This callback must not stop or destroy any watcher, ever, or
make any other event loop modifications whatsoever. If you
need to stop it, return now + 1030 and stop it
afterwards (e.g. by starting a
Prepare
watcher, which is the only event loop modification you are allowed to do). - If this callback raises an exception, or returns anything but a
float
, the module will stop the watcher.
- This callback must not stop or destroy any watcher, ever, or
make any other event loop modifications whatsoever. If you
need to stop it, return now + 1030 and stop it
afterwards (e.g. by starting a
-
at
¶ Read only
When active, this is the absolute time that the watcher is supposed to trigger next.
-