multimer

multimer: one Timer, one clock, one dispatcher, on every OmniPython host.

import multimer
from multimer import Timer

tim = Timer(-1)
tim.init(mode=Timer.PERIODIC, period=10, callback=on_tick)
sub = multimer.every(33, draw)
multimer.report()        # what is running, from the REPL

Callbacks run on the main thread at a safe point: between two bytecodes where the host can interrupt (a board, a signal, a pending call), otherwise at the next idle point (sleep_ms, pump, the REPL waiting for a key, an await). They never run on another thread and never inside a C call. Importing this package does nothing to the host; the wake source is chosen when the first timer is armed. See docs/guides/timers.md.

multimer.every(ms, callback, *, name=None)[source]

A PERIODIC Timer firing callback(timer) every ms.

multimer.after(ms, callback, *, name=None)[source]

A ONE_SHOT Timer firing callback(timer) once, after ms.

async multimer.asleep_ms(ms)[source]

Coroutine sleep for async code; delivers due timers on hosts without a wake source.

multimer.strategy()[source]

How the program stays alive past the script body: ambient, exit_hook, none, or None.

multimer.repl(namespace=None, prompt='>>> ', tick_ms=10)[source]

A line REPL that keeps delivering timers while it reads (hosts with no prompt).

multimer.report(file=None)[source]

Print the dispatcher’s state and every live timer, for a person at a prompt.