Skip to main content

MicroPython Cooperative Scheduler

A simple, lightweight, cooperative scheduler module designed for MicroPython.

License

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.

Metadata

Release files for mpy-scheduler 1.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mpy-scheduler 1.2.3
File Size Uploaded Provenance Actions
mpy_scheduler-1.2.3.tar.gz 8.3 kB Without provenance Details for mpy_scheduler-1.2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mpy-scheduler 1.2.3
File Interpreter ABI Platform Actions
mpy_scheduler-1.2.3-py3-none-any.whl Python 3 none any Details for mpy_scheduler-1.2.3-py3-none-any.whl

Total release size: 14.8 kB

Release files / mpy_scheduler-1.2.3.tar.gz

Download URL mpy_scheduler-1.2.3.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e449061686e0afd63ec410c500b874529e856aa0741b947733b76c78d2189b77
BLAKE2b-256 checksum
How to use checksums
28c97209c565f1337efe43f73a1981c81c1a97cf23efec2d5e436753fda28dac
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / mpy_scheduler-1.2.3-py3-none-any.whl

Download URL mpy_scheduler-1.2.3-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f4519ca67d16747d24a0ae8022cc929a72a90cf233131f67d618e0589e8214cc
BLAKE2b-256 checksum
How to use checksums
b4bbe939b4fef3d90ae48388c258381362a488dc6e4aa81493154a8cbea2a38a
Upload date
Uploaded using Trusted Publishing?
What is 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}

Security for mpy-scheduler 1.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.2.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page