bunpy.timers
Timers are available as globals in every bunpy script. They are also
importable from bunpy.timers.
from bunpy.timers import setTimeout, clearTimeout, setInterval, clearIntervalsetTimeout(fn, delay_ms) → id
Call fn after delay_ms milliseconds. Returns a timer ID.
tid = setTimeout(lambda: print("fired!"), 1000)clearTimeout(id)
Cancel a pending timeout.
clearTimeout(tid)setInterval(fn, interval_ms) → id
Call fn every interval_ms milliseconds. Returns a timer ID.
count = 0
iid = setInterval(lambda: (count := count + 1), 100)clearInterval(id)
Stop a repeating interval.
clearInterval(iid)Notes
- Timers run on goroutines. The callback is called from a separate goroutine.
- Use
threading.Lockif the callback mutates shared state. - A script exits when the main goroutine finishes, even if timers are pending.
Use
time.sleepor an event to keep the main goroutine alive.