Questions tagged [python-trio]

Trio is a Python package for async concurrency and I/O that's obsessed with usability and correctness

Official web site

52 questions
75
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
  • 14,837
  • 5
  • 37
  • 62
30
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,424
  • 16
  • 39
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
  • 5,872
  • 2
  • 27
  • 32
10
votes
4 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
  • 346
  • 3
  • 15
10
votes
1 answer

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
  • 553
  • 2
  • 6
  • 19
9
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
  • 4,433
  • 20
  • 37
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
  • 396
  • 3
  • 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
  • 193,422
  • 54
  • 273
  • 281
6
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
4
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

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

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,138
  • 2
  • 25
  • 40
3
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…
3
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…
3
votes
1 answer

Future/Promise like stuff for Trio in Python?

Say I have a class Messenger which is responsible for sending and receiving messages. Now I have a service that sends out requests and waits for responses via it, matching each pair with an id field in the message. In asyncio I would do: class…
lilydjwg
  • 1,424
  • 16
  • 39
1
2 3 4