bootstack.scheduling.Schedule#
- class bootstack.scheduling.Schedule(owner)#
Bases:
objectTimed task scheduler tied to a widget’s lifetime.
Runs callbacks after a delay, at idle, at an absolute time, or on a repeat, with automatic cleanup: all pending jobs are cancelled when the owner widget is destroyed.
Usage:
sched = widget.schedule # property on every public widget sched = Schedule(widget) # or construct directly job = sched.delay(500, callback) # one-shot after delay sched.idle(callback) # one-shot at next idle sched.at(datetime(...), callback) # one-shot at absolute time job = sched.every(1000, tick) # repeating every 1 second job.cancel() # cancel one job sched.cancel_all() # cancel everything
All jobs are automatically cancelled when
owneris destroyed.- Parameters:
owner (Any) – Widget that owns this scheduler. Its lifetime bounds all created jobs.
- at(when, fn, *args, **kwargs)#
Schedule
fnto run at an absolutedatetime.If
whenis in the past the job runs as soon as possible.
- cancel_all()#
Cancel all pending jobs created by this
Schedule.
- delay(ms, fn, *args, **kwargs)#
Schedule
fnto run once aftermsmilliseconds.
- every(ms, fn, *args, **kwargs)#
Schedule
fnto run repeatedly everymsmilliseconds.Compensates for callback execution time to reduce drift. If the callback raises an exception the interval is stopped and the exception is re-raised into the application’s error handler.
- idle(fn, *args, **kwargs)#
Schedule
fnto run once when the event loop is next idle.