Trio is a Python package for async concurrency and I/O that's obsessed with usability and correctness
Questions tagged [python-trio]
87 questions
2
votes
2 answers
How to manually exit an infinite trio-loop, like the trio's tutorial echo client
Is there a way to manually exit a trio infinite loop, like the echo client in the trio tutorial, https://trio.readthedocs.io/en/latest/tutorial.html#an-echo-client , other than using Ctrl-C or using timeouts?
My idea is to use call the echo client…

cloud ostrich
- 65
- 5
2
votes
1 answer
How to compact code that chooses how many concurrent tasks are made based on input?
I have a scraper project that works with the asynchronous requests asks library and trio.
I would like to chose how many concurrent tasks are made based on input, but my code is long and primitive
I use trio's spawning and nursery object for…

Tom
- 571
- 2
- 11
- 29
2
votes
1 answer
Trio: multiple tasks reading from the same fd
I have a file descriptor, and I would like to read from it with multiple tasks. Each read() request on the fd is going to return a full, independent packet of data (as long as data is available).
My naive implementation was to have each worker run…

Nikratio
- 2,338
- 2
- 29
- 43
1
vote
1 answer
Trio seems to start tasks in the nursery in exactly the opposite order that tasks were given at
I don't expect trio to run in any particular order. It is async, after all. But I noticed something strange and wanted to ask if anyone else could explain what might have happened:
I wanted to test the rate of data ingestion from Google's Pub Sub…

Mike Williamson
- 4,915
- 14
- 67
- 104
1
vote
1 answer
Trio: why are channels documented as using `async with`, rather than `with`?
Relevant documentation: https://trio.readthedocs.io/en/latest/reference-core.html#synchronizing-and-communicating-between-tasks
Relevant code: https://github.com/python-trio/trio/blob/master/trio/_channel.py
The documentation mentions, in close()…

Dubslow
- 553
- 2
- 6
- 15
1
vote
0 answers
Python send e-mail async with trio
I want to send e-mails in an asynchronous way by using the package trio. I found the package aiosmtplib, but this is only for asyncio.
Is there any package which I can use for it, or has anyone an idea of how to implement this with trio?
Update:
I…

Phil997
- 575
- 5
- 15
1
vote
2 answers
Wrapping a polling-based asynchronous API as an Awaitable
Consider some library with an interface like this:
RemoteTask.start()
RemoteTask.cancel()
RemoteTask.get_id()
RemoteTask.get_result()
RemoteTask.is_done()
For example, concurrent.futures.Future implements an API like this, but I don't want to…

shadowtalker
- 12,529
- 3
- 53
- 96
1
vote
1 answer
Python, Trio async function upon needs
Within trio/anyio, is it possible to pause the tasks until i do specific operation and then continue all of it.
Let's say that i run specific function to obtain a valid cookie and then i start to crawl a website, But after sometimes this cookie got…

αԋɱҽԃ αмєяιcαη
- 11,825
- 3
- 17
- 50
1
vote
1 answer
trio + httpx gives TrioDeprecationWarning
The following testcase gives a warning:
import trio, httpx
async def amain():
async with httpx.AsyncClient() as client:
r = await client.get('https://icanhazip.com/')
print(r.text)
trio.run(amain)
Output:
> python …

P i
- 29,020
- 36
- 159
- 267
1
vote
2 answers
Running trivial async code from sync in Python
I'm writing some parser code to be used with async IO functions (using Trio). The parser gets passed an object that exports an async read() method, and calls that method in the course of parsing.
Ordinarily, this code will be run using data straight…

Tom Hunt
- 916
- 7
- 21
1
vote
4 answers
Python Asyncio/Trio for Asynchronous Computing/Fetching
I am looking for a way to efficiently fetch a chunk of values from disk, and then perform computation/calculations on the chunk. My thought was a for loop that would run the disk fetching task first, then run the computation on the fetched data. I…

stillQuestioning
- 105
- 3
- 10
1
vote
1 answer
Migrating a Quart project with websockets from asyncio to trio
I'm trying to convert my asyncio project to trio.
I understand that I have to use memory channels instead of Queues but for some reason I don't have the result I'm expecting.
My main problem is that when I run two clients, the first one does not get…

tibs
- 13
- 3
1
vote
1 answer
How to safely close a connection in Trio?
I have the application logic for a connection all wrapped in a big try/except/finally block:
async def serve(self, stream: trio.SocketStream):
try:
async with trio.open_nursery() as nursery:
pass # code goes here to do some…

Arthur Tacca
- 8,833
- 2
- 31
- 49
1
vote
1 answer
How could I asynchronously read a specific line of a file with trio
So I'd like to open files with trio (asynchronously) and then as the file is rather large read a single specific line of it
So in "normal" synchronous python, I'd do something like this:
with open("text.txt") as f:
for i, line in enumerate(f):
…

Tom
- 571
- 2
- 11
- 29
1
vote
1 answer
Request using trio asks returns a different response than with requests and aiohttp
Right, hello, so I'm trying to implement opticard (loyality card services) with my webapp using trio and asks (https://asks.readthedocs.io/).
So I'd like to send a request to their inquiry api:
Here goes using requests:
import requests
r =…

Tom
- 571
- 2
- 11
- 29