MicroPython Cooperative Scheduler
A simple, lightweight, cooperative scheduler module designed for MicroPython.
Installation
Via mip
You can install this package directly onto your MicroPython device using mip:
import mip
mip.install("github:simonl65/scheduler")
Or using mpremote:
mpremote mip install github:simonl65/scheduler
Via uv / pip (For development/simulation)
For local simulation or development, you can install the package via:
uv pip install .
# or
pip install .
Usage
Define your task functions and task list, and run the scheduler loop:
from machine import Pin
from scheduler import Task, run
led = Pin("LED", Pin.OUT)
def task_led():
led.toggle()
print("LED toggled")
def task_sensor():
print("Reading sensor data")
# Set up tasks with their intervals (in milliseconds)
tasks = [
Task(task_led, interval_ms=1000),
Task(task_sensor, interval_ms=500),
]
# Build the generator once, outside the loop.
# Setting light_sleep=True will sleep between task rounds to save power.
scheduler = run(tasks, light_sleep=True)
while True:
next(scheduler)
A task's exception is isolated by default -- caught and stashed on
task.last_exception so one failing callback doesn't stop the round or later
tasks in it. Pass Task(..., isolate_errors=False) for a task whose failure
must propagate and stop the loop instead.
light_sleep caveat
light_sleep=True calls machine.lightsleep() between rounds, which stops
the device responding to everything outside of a Task callback for up to
the soonest task's remaining interval -- including any UART, SPI, or other
peripheral serviced by application code between next(scheduler) calls.
Bytes arriving during the sleep are lost with no indication to the caller.
Only enable it on a device where all I/O happens inside Task callbacks.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mpy_scheduler-1.2.3.tar.gz.
File metadata
- Download URL: mpy_scheduler-1.2.3.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Zorin OS","version":"18","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e449061686e0afd63ec410c500b874529e856aa0741b947733b76c78d2189b77
|
|
| MD5 |
04f8ec09ee4a1980efadd4e0ade1460c
|
|
| BLAKE2b-256 |
28c97209c565f1337efe43f73a1981c81c1a97cf23efec2d5e436753fda28dac
|
File details
Details for the file mpy_scheduler-1.2.3-py3-none-any.whl.
File metadata
- Download URL: mpy_scheduler-1.2.3-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Zorin OS","version":"18","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4519ca67d16747d24a0ae8022cc929a72a90cf233131f67d618e0589e8214cc
|
|
| MD5 |
1acb57a37596b1529e3bd20f5be2820d
|
|
| BLAKE2b-256 |
b4bbe939b4fef3d90ae48388c258381362a488dc6e4aa81493154a8cbea2a38a
|