Skip to main content

A re-implementation of the asyncio mainloop on top of Trio

Project description

trio-asyncio is a re-implementation of the asyncio mainloop on top of Trio.

Rationale

There are quite a few asyncio-compatible libraries.

On the other hand, Trio has native concepts of tasks and task cancellation. Asyncio, on the other hand, is based on chaining Future objects, albeit with nicer syntax.

Thus, being able to use asyncio libraries from Trio is useful.

Principle of operation

The core of the “normal” asyncio main loop is the repeated execution of synchronous code that’s submitted to call_soon or add_reader/add_writer.

Everything else within asyncio, i.e. Futures and async/await, is just syntactic sugar. There is no concept of a task; while a Future can be cancelled, that in itself doesn’t affect the code responsible for fulfilling it.

On the other hand, trio has genuine tasks with no separation between returning a value asynchronously, and the code responsible for providing that value.

trio_asyncio implements a task which runs (its own version of) the asyncio main loop. It also contains shim code which translates between these concepts as transparently and correctly as possible, and it supplants a few of the standard loop’s key functions.

This works rather well: trio_asyncio consists of just ~700 lines of code (asyncio: ~8000) but passes the complete Python 3.6 test suite with no errors.

Author

Matthias Urlichs <matthias@urlichs.de>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trio_asyncio-0.7.5.tar.gz (117.0 kB view details)

Uploaded Source

File details

Details for the file trio_asyncio-0.7.5.tar.gz.

File metadata

File hashes

Hashes for trio_asyncio-0.7.5.tar.gz
Algorithm Hash digest
SHA256 fd131c3c72b2eb51f5eb98075a34a85dfe1a7acc61ea24bcf5757a2187f0ff6f
MD5 9972213f9ca08be035ed16d92bc9dbf2
BLAKE2b-256 fd4229e27cecd1ac39b3b69c754fa5c5f683dc3ddfc88e72ae5367bd3d648ce6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page