Trio is a Python package for async concurrency and I/O that's obsessed with usability and correctness
Questions tagged [python-trio]
87 questions
119
votes
1 answer
What is the core difference between asyncio and trio?
Today, I found a library named trio which says itself is an asynchronous API for humans. These words are a little similar with requests'. As requests is really a good library, I am wondering what is the advantages of trio.
There aren't many articles…

Sraw
- 18,892
- 11
- 54
- 87
36
votes
1 answer
In trio, how can I have a background task that lives as long as my object does?
I'm writing a class that will spawn tasks during its lifetime. Since I'm using Trio, I can't spawn tasks without a nursery. My first thought was to have a self._nursery in my class that I can spawn tasks into. But it seems that nursery objects can…

lilydjwg
- 1,621
- 20
- 41
15
votes
5 answers
How to gather task results in Trio?
I wrote a script that uses a nursery and the asks module to loop through and call an API based upon the loop variables. I get responses but don't know how to return the data like you would with asyncio.
I also have a question on limiting the APIs…

jleatham
- 456
- 8
- 17
12
votes
2 answers
async trio way to solve Hettinger's example
Raymond Hettinger gave a talk on concurrency in python, where one of examples looked like that:
import urllib.request
sites = [
'https://www.yahoo.com/',
'http://www.cnn.com',
'http://www.python.org',
'http://www.jython.org',
…

Grail Finder
- 635
- 2
- 7
- 21
11
votes
3 answers
Run tests concurrently
I would like to run several tests concurrently using asyncio (/curio/trio) and pytest, but I couldn't find any information on that. Do I need to schedule them myself? And if I do, is there a way to have a nice output that separates (sub-)tests…

cglacet
- 8,873
- 4
- 45
- 60
11
votes
2 answers
Capture the return value from nursery objects
When using trio and nursery objects, how do you capture any value that was returned from a method?
Take this example from the trio website:
async def append_fruits():
fruits = []
fruits.append("Apple")
fruits.append("Orange")
return…
user10146913
10
votes
3 answers
How can I read one line at a time from a trio ReceiveStream?
asyncio has StreamReader.readline(), allowing something like:
while True:
line = await reader.readline()
...
(I don't see async for available in asyncio but that would be the obvious evolution)
How do I achieve the equivalent with trio?
I…

Robie Basak
- 6,492
- 2
- 30
- 34
9
votes
1 answer
Trio execution time without IO operations
I'm doing examples to understand how it works python asynchronously. I read the Trio documentation and I thought that only one task can be executed in the loop every time and in every checkpoint the scheduler decide which task will be executed.
I…

Pentux
- 406
- 4
- 13
6
votes
1 answer
Detecting current async library
I'm writing some async library and decided to support both asyncio and trio concurrency libraries to run it. I have some code that tries to be clever and do the right thing no matter which library was chosen.
How can I detect which one of those was…

nosklo
- 217,122
- 57
- 293
- 297
5
votes
1 answer
Python - How to cancel a specific task spawned by a nursery in python-trio
I have an async function that listens on a specific port. I want to run the function on a few ports at a time and when the user wants to stop listening on a specific port, stop the function listening on that port.
Previously I was using the asyncio…
user12532791
4
votes
1 answer
Is yielding from inside a nursery in an asynchronous generator function bad?
I was told that the following code is not safe, because it is not allowed to have an asynchronous generator that yields from inside a nursery, except if it is an asynchronous context manager.
T = TypeVar('T')
async def delay(interval: float,…

Anders E. Andersen
- 1,635
- 2
- 14
- 20
4
votes
1 answer
Async named pipes in windows using trio and python
Is there any way to use async named pipes in trio under windows? I have two applications that should communicate using named pipes. One is running C# (this is not a problem) and the other is running python.
I have tried to dig a little, but have not…

PetarMignon
- 43
- 3
4
votes
1 answer
Getting OSError: (Address already in use) while runnning a function that uses trio-sockets in a while loop
Code
import trio
from trio import socket
async def listen(host, port):
while True:
fullmsg = ""
sock = socket.socket()
await sock.bind((host, port))
sock.listen()
print(f'Awaiting Receive On…
user12532791
4
votes
1 answer
How to use python-trio with google protocol buffer?
I am trying to read some data streams using protobuf in python, and i want to use trio to make the client for reading the streams. The protobuf has some method calls, and i find they do not work when i use trio streams.
Python client on a linux…

cloud ostrich
- 65
- 5
4
votes
1 answer
trio nursery that doesn't cancel all tasks if one fails
I'd like to implement a server with trio. Individual client connections are handled by tasks spawned by a nursery. However, the trio docs say that "If any task inside the nursery finishes with an unhandled exception, then the nursery immediately…

Nikratio
- 2,338
- 2
- 29
- 43