Skip to main content
Latest PyPI version Automated test status Test coverage Code style: black

Trio, an alternate async framework for Python, supports a feature called “guest mode” where it can run in the same thread as another event loop. In guest mode, low-level I/O waiting occurs on a worker thread, but the threading is invisible to user code, and both event loops can interact with each other without any special synchronization.

This package implements guest mode for asyncio. It has one public function:

aioguest.start_guest_run(
    coro,
    *,
    run_sync_soon_threadsafe,
    done_callback,
    run_sync_soon_not_threadsafe=None,
    debug=None,
    loop_factory=None,
)

This effectively starts a call to asyncio.run(coro) in parallel with the currently running (“host”) event loop. The debug parameter is passed to asyncio.run() if specified. On Python 3.11+, you can also supply a loop_factory which will be passed to asyncio.Runner().

The parameters run_sync_soon_threadsafe, done_callback, and (optionally) run_sync_soon_not_threadsafe tell aioguest how to interact with the host event loop. Someday aioguest will have documentation of its own. Until then, see the Trio documentation for details on these parameters, including an example.

start_guest_run() returns the main task of the new asyncio run, i.e., the asyncio.Task that wraps coro. It may also return None if the main task could not be determined, such as because asyncio.run() raised an exception before starting to execute coro. The main task is provided mostly for cancellation purposes; while you can also register callbacks upon its completion, the run is not necessarily finished at that point, because background tasks and async generators might still be in the process of finalization.

Exceptions noticed when starting up the asyncio run might either propagate out of start_guest_run() or be delivered to your done_callback, maybe even before start_guest_run() returns (it will return None in that case). In general, problems noticed by aioguest will propagate out of start_guest_run(), while problems noticed by asyncio will be delivered to your done_callback.

aioguest requires Python 3.8 or later. Out of the box it supports the default asyncio event loop implementation (only) on Linux, Windows, macOS, FreeBSD, and maybe others. It does not support operating systems that provide only select() or poll(); due to thread-safety considerations it needs an I/O abstraction where the OS kernel is involved in registrations, such as IOCP, epoll, or kqueue. Alternative Python-based event loops can likely be supported given modest effort if they use such an abstraction. Alternative C-based event loops (such as uvloop) present much more of a challenge because compiled code generally can’t be monkeypatched.

Development status

aioguest has been tested with a variety of toy examples and pathological cases, and its unit tests exercise full coverage. It hasn’t had a lot of exposure to real-world problems yet. Maybe you’d like to expose it to yours?

License

aioguest is licensed under your choice of the MIT or Apache 2.0 license. See LICENSE for details.

Metadata

Release files for aioguest 0.1.0

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

Source distribution (sdist)

Source distribution for aioguest 0.1.0
File Size Uploaded Provenance
aioguest-0.1.0.tar.gz 25.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aioguest 0.1.0
File Interpreter ABI Platform
aioguest-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 43.0 kB

Release files / aioguest-0.1.0.tar.gz

Download URL aioguest-0.1.0.tar.gz
Size 25.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b0bad95272592703379ada3d69f442c73b2cb64075be21d8617049c75747904b
BLAKE2b-256 checksum
How to use checksums
777777d0701a2b13d202de41809e3942d98596f2c791aadd94f4d3bcf2791a4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / aioguest-0.1.0-py3-none-any.whl

Download URL aioguest-0.1.0-py3-none-any.whl
Size 17.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2f993e173503638a61e8f51b5f5f71ed0b9cfdb782b208d3822d10904cd0af75
BLAKE2b-256 checksum
How to use checksums
90ddfbdcc568d3655c626f6f5e08b91eeeb1497208f012c12cc87abc5afbcd3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Security for aioguest 0.1.0

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

0.1.0 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