Skip to main content

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 SIGINT and SIGTERM handlers so Ctrl+C or an orchestrator can stop the loop cleanly;
  • validates that the provided context function is an async generator with one yield, otherwise raises RuntimeError;
  • exposes Runner.stop() so any coroutine can request shutdown;
  • forwards the debug flag to asyncio.run for 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:

  1. Prepare resources before yield (servers, background tasks, DB pools).
  2. yield once. A second yield triggers RuntimeError.
  3. After yield, perform cleanup. Calling runner.stop() before run() or after shutdown raises RuntimeError to help catch lifecycle bugs.

API surface

Runner(
    context_function: ContextFunction,
    *,
    debug: bool = False,
    **kwargs: Any,
)
  • context_function must be async def context(runner, **kwargs) -> AsyncIterator[None].
  • debug toggles asyncio.run(..., debug=True).
  • **kwargs are 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 .venv aligned with uv.lock.
  • Automation lives in mise.toml; run mise run lint, mise run basedpyright, mise run mypy, mise run test, or the umbrella mise run all to reuse the exact CI commands.
  • Hook runner: we lean on prek with the same .pre-commit-config.yaml used in CI. Install it via uvx prek install and run uvx prek run --all (or uvx prek run basedpyright, etc.) before committing.
  • Additional helpers exist as mise run format, mise run coverage, mise run build, and mise run upload for releases.
  • tox targets py311, py312, py313, and lint so 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)

Source distribution for aiorunner 0.2.5
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)

Table of built distributions (wheels) for aiorunner 0.2.5
File Interpreter ABI Platform Actions
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.

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