trio-future
Overview
trio-future allows you to capture the return values of concurrently executed trio functions. It's an altnerative to using trio channels to communicate results between tasks that feels more like programming with normal functions.
Consider an example with this simple echo function:
async def echo(a: str) -> str:
await trio.sleep(0.5)
return a
We can call our function and get its result back later when we are ready:
async with trio.open_nursery() as nursery:
# Call trio_future.run to synchronously get back a Future
future = trio_future.run(nursery, echo, "hello")
# When we call `await` and yield to scheduler, our function begins executing
await trio.sleep(0.1)
# We can `await` the function when we are ready
hello = await future.get()
# hello == "hello"
A common use-case is to run several tasks concurrently and wait for them all to complete. trio-future has a gather function like asyncio.gather to do this:
async with trio.open_nursery() as nursery:
fut_1 = run(nursery, echo, "hello")
fut_2 = run(nursery, echo, "world")
# Call `gather` to package the two Futures into a single Future object.
# Note that this is again a synchronous function.
joined_future = gather(nursery, [fut_1, fut_2])
# Again, when we `await` the result, we yield to the scheduler. This time, both
# of our futures will execute concurrently.
hello_world = await join_future.get()
# hello_world = ["hello", "world"]
Metadata
Release files for trio-future 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| trio-future-0.1.1.tar.gz | 4.2 kB | Without provenance | Details for trio-future-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| trio_future-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for trio_future-0.1.1-py3-none-any.whl |
Total release size: 8.6 kB
Release files / trio-future-0.1.1.tar.gz
| Download URL | trio-future-0.1.1.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
251d19e60b5129f8812f8b4a421517a4be98fdea2f90bb14c5d55084263d7991
|
|
BLAKE2b-256 checksum How to use checksums |
5baca08e85ed9906b1551786c5b77d24490ced75bf2ce6ad0fbe53f06fe2fe53
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.9.0 Darwin/18.7.0
|
Release files / trio_future-0.1.1-py3-none-any.whl
| Download URL | trio_future-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
222791e1fd5700ad2422393d98a9c3a23d264ff3058d8a7f263e1ba608e6d898
|
|
BLAKE2b-256 checksum How to use checksums |
e428d50c01259d16b0ab7af968f1cc37347cce6f706e3a902f58d7ea17ba99de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.9.0 Darwin/18.7.0
|
Security for trio-future 0.1.1
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.