Backport of asyncio.Runner, a context manager that controls event loop life cycle.
Low maintenance activity. Last release 17 months ago, commits in 0 of the last 26 weeks. Weaker on commit activity and recent releases. It brings a standard-library module to older Pythons: on current versions, use the built-in one.
pip install backports-asyncio-runnerbackports.asyncio.runner
This is a backport of Python 3.11 asyncio.Runner, a context manager that simplifies multiple async function calls in the same context.
This backports provides full compatibility with Python 3.11 asyncio.Runner features, including contextvars.Context support.
As such, the Python 3.11 test suite for asyncio.Runner is used as-is to test its functionality.
This backport is meant to work with Python 3.8, 3.9, and 3.10 only. Users of Python 3.11 or above should not use this package directly.
To install, you can use python -m pip install backports.asyncio.runner or your favorite python package manager.
You might need to include a marker (e.g. python_version < '3.11') to prevent installation on Python 3.11 or above.
An example of the recommended way to use this context manager is in the below code snippet:
import sys
if sys.version_info < (3, 11):
from backports.asyncio.runner import Runner
else:
from asyncio import Runner
async def echo(msg: str) -> None:
print(f"Hello {msg}")
with Runner() as runner:
runner.run(echo("World"))
# Hello World