Scheduler — Scheduler watcher

class Scheduler(reschedule, loop[, callback=None, data=None, priority=0])
Parameters:
  • reschedule (callable) – reschedule callback.
  • loop (Loop) – loop object responsible for this watcher (accessible through loop).
  • callback (callable) – see callback.
  • data (object) – any Python object you might want to attach to the watcher (stored in data).
  • priority (int) – see priority.

Scheduler watchers are specialised Periodic watchers. Each time the Scheduler watcher gets scheduled, the reschedule 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:

reschedule(watcher, now)
Parameters:
  • watcher (Scheduler) – this watcher.
  • now (float) – the current time.
Return type:

float

Returns:

the next time to trigger.

It must always return a float greater than or equal to the now argument to indicate the next time the watcher callback should be invoked. It will usually be called just before the callback 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.
at

Read only

When active, this is the absolute time that the watcher is supposed to trigger next.