On this page
sched.scheduler
Up: sched
Rel: sched
Ref: docs.python.org — sched.scheduler
Tags: #public #python3 #stdlib #sched
Import
import sched
from sched import scheduler
Signature & Overview
sched.scheduler(timefunc=<built-in function monotonic>, delayfunc=<built-in function sleep>)
sched.scheduler class.
Methods & Attributes
scheduler.cancel(self, event)— Remove an event from the queue.scheduler.empty(self)— Check whether the queue is empty.scheduler.enter(self, delay, priority, action, argument=(), kwargs=<object object at 0x1040b5960>)— A variant that specifies the time as a relative time.scheduler.enterabs(self, time, priority, action, argument=(), kwargs=<object object at 0x1040b5960>)— Enter a new event in the queue at an absolute time.scheduler.queue(...)— An ordered list of upcoming events.scheduler.run(self, blocking=True)— Execute events until the queue is empty.
Usage
import sched
clock = 0.0
out: list[float] = []
def advance(dt):
global clock
clock += dt
s = sched.scheduler(lambda: clock, advance)
s.enter(10.0, 1, lambda: out.append(clock))
s.run()
assert out == [10.0]
Gotchas
- Single-threaded & blocking: Use
time.monotonicin real code (nottime.time), and cancel events via theEventtoken returned byenter().
REPL Inspect
from sched import scheduler
help(scheduler)
Linked from
Related notes
- tuts/python3/stdlib_module/sched Linked here; links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib
- tuts/c/stdlib/ctype shared tags: #stdlib
- tuts/c/stdlib/ctype/isalpha shared tags: #stdlib
- tuts/c/stdlib/ctype/isdigit shared tags: #stdlib
- tuts/c/stdlib/ctype/isspace shared tags: #stdlib
- tuts/c/stdlib/ctype/tolower shared tags: #stdlib