Scheduler — Scheduler watcher

class pyev.Scheduler(scheduler, loop, callback[, data=None, priority=0])
Parameters:

Scheduler watchers are specialised Periodic watchers. Each time the Scheduler gets scheduled, the reshedule callback (scheduler) will be called with the watcher as first, and the current time as second argument. Example:

def myscheduler(watcher, now):
    return now + 60.0

Scheduler(myscheduler, ...)

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 periodic watcher again. This is only useful when scheduler would return a different time than the last time it was called (e.g. in a crond like program when the crontabs have changed).

at() → float

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

scheduler

The current reschedule callback. Can be changed any time.

Its signature must be:

scheduler(watcher, now) → float
Parameters:
  • watcher (Scheduler) – this watcher.
  • now (float) – the current time.

It must return a float greater than or equal to the now argument to indicate the next time the watcher callback should be scheduled. It will usually be called just before the callback will be 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 + 1e+30 and stop it afterwards (e.g. by starting a Prepare watcher, which is the only event loop modification you are allowed to do).
  • If the reshedule callback raises an error, or returns anything but a float, pyev will stop this watcher.

Previous topic

Periodic — Periodic watcher

Next topic

Signal — Signal watcher

This Page