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.

trio_asyncio requires Python 3.8 or later.

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.14.1.tar.gz (73.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trio_asyncio-0.14.1-py3-none-any.whl (38.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: trio_asyncio-0.14.1.tar.gz
  • Upload date:
  • Size: 73.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for trio_asyncio-0.14.1.tar.gz
Algorithm Hash digest
SHA256 558e9fd4f6fe7f3809382ea1778d34104726435d86adc91097a7c2c163235dcb
MD5 a33f9ad9ec83c7dbee5acc9ff70de0a6
BLAKE2b-256 a04499899ee830ce33b3115485b6a768fb1d69d42cef54a7f4cda3147abd9cc3

See more details on using hashes here.

File details

Details for the file trio_asyncio-0.14.1-py3-none-any.whl.

File metadata

  • Download URL: trio_asyncio-0.14.1-py3-none-any.whl
  • Upload date:
  • Size: 38.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for trio_asyncio-0.14.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f7e6b2ddd70908c9f624f2deb7e645550db998e4c988593592ff9f62352ae419
MD5 fe6170d07152373476424933fba2b80d
BLAKE2b-256 8ac484e7c269ea792300968de042b8ef6e440bef4acab9439fd7fb258270c667

See more details on using hashes here.

Supported by

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