API Reference¶
chumicro_runner¶
chumicro_runner
¶
Public exports for the chumicro-runner package.
ReentrantTickError
¶
Bases: RuntimeError
Raised when tick() runs while another tick() is in progress.
Runner
¶
Run tasks on a tick-based schedule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ticks
|
object | None
|
Optional source ( |
None
|
poller
|
object | None
|
Optional poll object (register/modify/unregister/ipoll); default |
None
|
on_handler_error
|
object | None
|
Optional |
None
|
add(task=None, handler=None, period_ms=None, start_after_ms=None, run_count=None, preserve_phase=False)
¶
Register a task with the runner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
object | None
|
Object with |
None
|
handler
|
object | None
|
Callable |
None
|
period_ms
|
int | None
|
Optional interval in milliseconds. |
None
|
start_after_ms
|
int | None
|
Optional initial delay before the first fire; overrides the first period. |
None
|
run_count
|
int | None
|
Optional number of fires before auto-removing; |
None
|
preserve_phase
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
TaskHandle
|
A |
add_generator(generator)
¶
Register a generator-driven service with the runner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
generator
|
object
|
A fresh, not-yet-advanced generator; this method primes it to its first yield. |
required |
Returns:
| Type | Description |
|---|---|
GeneratorHandle
|
A |
add_periodic(handler, period_ms, start_after_ms=None, run_count=None, preserve_phase=False)
¶
Register a periodic handler with no check.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
object
|
Callable |
required |
period_ms
|
int
|
Interval in milliseconds (required). |
required |
start_after_ms
|
int | None
|
Optional initial delay before the first fire. |
None
|
run_count
|
int | None
|
Optional number of fires before auto-removing; |
None
|
preserve_phase
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
TaskHandle
|
A |
tick()
¶
Capture time, check tasks, then batch-fire due handlers.
Returns:
| Type | Description |
|---|---|
int
|
The tick timestamp used this cycle. |
Raises:
| Type | Description |
|---|---|
ReentrantTickError
|
A handler called |
wait(now_ms)
¶
Idle until a registered socket is ready or the next deadline arrives.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
now_ms
|
int
|
Current tick, typically the value returned by the preceding |
required |
run_until(predicate=None, *, timeout_ms=None)
¶
Drive tick() and wait() until predicate is truthy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predicate
|
object | None
|
A handle (exposes |
None
|
timeout_ms
|
int | None
|
Optional budget (ms), checked between ticks; best-effort under socket waits. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
BaseException
|
The handle form re-raises |
TaskHandle
¶
Handle returned by Runner.add() or add_periodic().
set_period(period_ms, now_ms=None)
¶
Add, change, or remove the period for this task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
period_ms
|
int | None
|
New interval in milliseconds, or |
required |
now_ms
|
int | None
|
Anchor for the next fire, typically the timestamp the enclosing
|
None
|
remove()
¶
Remove this task from the runner.
chumicro_runner.generators¶
Suspension helper for generators registered with Runner.add_generator. yield from sleep_until(until_ms) parks the generator until the clock reaches that absolute tick, and the runner keeps serving every other service meanwhile. Registration hands back a GeneratorHandle carrying .done, .error, and .cancel(). Import this module explicitly; a program with no generators never loads it.
chumicro_runner.generators
¶
Suspension helpers for runner-driven generators.
sleep_until suspends a generator registered via Runner.add_generator until an absolute tick arrives.
sleep_until(until_ms)
¶
Suspend the generator until ticks_ms() >= until_ms.
Does no time math of its own: it publishes the deadline and the driver decides
when to resume, comparing with the clock it was built on. That keeps a sleep
measured in the units of the clock passed to Runner(ticks=...) rather than
a second one this module reached for.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
until_ms
|
int
|
Absolute tick value at which to resume, in the driver's units. |
required |
Yields:
| Type | Description |
|---|---|
object
|
A private deadline-wait carrying until_ms. |