Asyncer is a small Python library built on top of AnyIO, focused on improving developer experience when working with `async` and `await` and mixing async with regular blocking code. It provides utility functions like `asyncify` and `syncify` to bridge asynchronous and synchronous code more conveniently, offering better editor support and type checking. It is actively maintained, with frequent minor releases.
pip install asyncerVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use `asyncer.asyncify` to call a regular blocking function (`blocking_function`) from within an asynchronous context (`main`). `asyncify` ensures the blocking operation runs in a worker thread, preventing it from blocking the main event loop. The `anyio.run(main)` call starts the AnyIO event loop to execute the asynchronous `main` function.
Upgrade to Python 3.10 or higher, or pin Asyncer to `<0.0.15`.
Upgrade to Python 3.9 or higher (preferably 3.10+), or pin Asyncer to `<0.0.12`.
Replace `asyncify(..., cancellable=True)` with `asyncify(..., abandon_on_cancel=True)`. Refer to AnyIO documentation for precise behavior of `abandon_on_cancel`.
Ensure `asyncer` functions are used within an appropriate asynchronous context (e.g., `anyio.run()`) or explicitly handle synchronous execution with `syncify(..., raise_sync_error=False)`.
Pin the Asyncer version in your `requirements.txt` or `pyproject.toml` (e.g., `asyncer==0.0.17`) and maintain comprehensive tests to ensure compatibility when upgrading.
Install the 'asyncer' library using pip: 'pip install asyncer'.
Rename the variable or module named 'async' to avoid using reserved keywords.
Ensure that all coroutines are awaited using 'await' or run with an event loop.
Ensure the event loop is open before performing asynchronous operations.
Verify the correct usage and attributes of the 'asyncio' module as per the official documentation.