Aiorunner
Tiny wrapper around asyncio that starts long running tasks, installs
SIGINT/SIGTERM handlers, and guarantees a single cleanup point for your
application.
Highlights
- registers
SIGINTandSIGTERMhandlers soCtrl+Cor an orchestrator can stop the loop cleanly; - validates that the provided context function is an async generator with one
yield, otherwise raisesRuntimeError; - exposes
Runner.stop()so any coroutine can request shutdown; - forwards the
debugflag toasyncio.runfor richer diagnostics.
Installation
pip install aiorunner
Requires Python 3.11-3.14 (see pyproject.toml).
Quick start
import asyncio
from collections.abc import AsyncIterator
from aiorunner import Runner
async def app(runner: Runner) -> AsyncIterator[None]:
task = asyncio.create_task(asyncio.sleep(3600))
print("Ready")
yield # blocks until Ctrl+C or runner.stop()
task.cancel()
print("Bye")
Runner(app, debug=True).run()
Inside your context function:
- Prepare resources before
yield(servers, background tasks, DB pools). yieldonce. A secondyieldtriggersRuntimeError.- After
yield, perform cleanup. Callingrunner.stop()beforerun()or after shutdown raisesRuntimeErrorto help catch lifecycle bugs.
API surface
Runner(
context_function: ContextFunction,
*,
debug: bool = False,
**kwargs: Any,
)
context_functionmust beasync def context(runner, **kwargs) -> AsyncIterator[None].debugtogglesasyncio.run(..., debug=True).**kwargsare forwarded to the context function.
Methods:
run()starts the event loop and blocks until cleanup finishes.stop()can be scheduled from any task or thread via.
Observability
The package logger aiorunner logs DEBUG messages when entering the wait
loop, receiving a signal, and exiting cleanup. Configure logging handlers in
your app to surface these breadcrumbs.
Development
- Create/update the virtual environment with
uv sync --group dev; this keeps.venvaligned withuv.lock. - Automation lives in
mise.toml; runmise run lint,mise run basedpyright,mise run mypy,mise run test, or the umbrellamise run allto reuse the exact CI commands. - Hook runner: we lean on prek with the same
.pre-commit-config.yamlused in CI. Install it viauvx prek installand runuvx prek run --all(oruvx prek run basedpyright, etc.) before committing. - Additional helpers exist as
mise run format,mise run coverage,mise run build, andmise run uploadfor releases. toxtargetspy311,py312,py313, andlintso CI can mirror local runs.
License
MIT, see LICENSE.
Metadata
Release files for aiorunner 0.2.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aiorunner-0.2.5.tar.gz | 4.8 kB | Without provenance | Details for aiorunner-0.2.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aiorunner-0.2.5-py3-none-any.whl | Python 3 | none | any | Details for aiorunner-0.2.5-py3-none-any.whl |
Total release size: 9.9 kB
Release files / aiorunner-0.2.5.tar.gz
| Download URL | aiorunner-0.2.5.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
56e4fb940fc086fc7db5db8b7dcf50522a51e55710256c0c887f2efe01cebf2b
|
|
BLAKE2b-256 checksum How to use checksums |
85a70706dbdfded7c5f2d1fa163e7a3b716925fa82099a80a8457df22e99fada
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / aiorunner-0.2.5-py3-none-any.whl
| Download URL | aiorunner-0.2.5-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c39357592a6429a21d8bdef2cbcb933a7b491ff27dcb2bf245b9a2dbaeff54f2
|
|
BLAKE2b-256 checksum How to use checksums |
315c5d23dbbc1e19cb174e43389358b65a97ee24cfaef9ac8e98762cd78b36a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for aiorunner 0.2.5
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.