Trio is a Python package for async concurrency and I/O that's obsessed with usability and correctness
Questions tagged [python-trio]
87 questions
1
vote
2 answers
python web scraping from a list of urls
I am new in asks and trio in python, I got a sample code. let me explain
I have a list of URL every one is news URLs, each one has sub urls.
the first url requests and get all other hrefs and add in a list.
then get the article of all hrefs in that…

newuser
- 61
- 1
- 10
1
vote
2 answers
Combining trio and flask
I'm trying to make an HTTP API that can create and destroy concurrent tasks that open TCP connections to remote servers streaming ~15-second data. I'll have to figure out how to handle the data later. For now I just print it.
In the example below, I…

hankivstmb
- 171
- 2
- 10
1
vote
2 answers
Python: ways to synchronize trio tasks and regular threads
I find myself in the situation that I need to synchronize Trio tasks with Python threads. At the moment, I am using threading.Lock objects that Trio tasks have to acquire with trio.run_sync_in_worker_thread(lock.acquire).
I think it should also be…

Nikratio
- 2,338
- 2
- 29
- 43
1
vote
1 answer
TRIO Lib queue get and put
Hello I'm trying to use trio with two asyncronous functions and a message in between. but it doesn't launch the consumer and I don't really understand why . The producer sends well in the'queue' and does not send anything once it is saturated. But…

Pascal de Sélys
- 127
- 1
- 10
1
vote
5 answers
Spawn processes and communicate between processes in a trio based Python application
For an internship on the Python library fluidimage, we are investigating if it could be a good idea to write a HPC parallel application with a client/servers model using the library trio.
For asynchronous programming and i/o, trio is indeed…

paugier
- 1,838
- 2
- 20
- 39
0
votes
1 answer
Asynchronous Streaming of Notifications with Mastodon.py
I am attempting to asynchronously stream notifications from Mastodon using Mastodon.py. To run the asynchronous code, I'm attempting to use Trio
I've tried the following:
...
from mastodon import Mastodon, StreamListener
...
def main():
...
…

slashtechno
- 11
- 5
0
votes
2 answers
Call trio from inside a greenlet
I've tried this:
import trio
from gevent import monkey, spawn
monkey.patch_all()
async def async_double(x):
return 2 * x
def run():
return trio.run(async_double, 3)
g = spawn(run)
g.join()
But I get an error:
Traceback (most recent call…

Cyberwiz
- 11,027
- 3
- 20
- 40
0
votes
1 answer
How to measure time spent inside Python trio coroutine?
For testing purposes, I would like to measure the time that is spent on blocking execution of a coroutine (i.e, excluding the time for which it is suspended).
For example:
import trio
import time
async def under_test():
await trio.sleep(2)
…

Nikratio
- 2,338
- 2
- 29
- 43
0
votes
1 answer
Problem with Trio package when installing pymongo in my project
i have a django project that runs on ubuntu 20.04 version.
i use selenium versio 4.1.5 .
the selenium package has the trio package as a dependecy (version 0.22.2).
until i added pymongo version (4.4.1) to my project everything worked fine.
when…
0
votes
2 answers
How to find out how often a Python coroutine is suspended when using Trio
Is there a way to find out how often a coroutine has been suspended?
For example:
import trio
async def sleep(count: int):
for _ in range(count):
await trio.sleep(1)
async def test():
with track_suspensions() as ctx:
await…

Nikratio
- 2,338
- 2
- 29
- 43
0
votes
1 answer
What is the correct syntax to spawn a process with "await nursery.start(trio.run_process, ...)"?
I want to spawn a process and get the process-object for further processing.
But I got an error when I use arguments. What am I doing wrong?
Here is my script:
import trio
from subprocess import PIPE
VAR = {'prg': None}
async def main():
async…

Peter
- 3
- 3
0
votes
0 answers
error message after using trio.lowlevel.open_process and feeding data to stdin
I prepared an asynchronous python-script using trio to receive internet-radio and playback audio using VLC.
The receiver part is based on httpx and is running well. The audio part uses cvlc - the VLC-commandline-version and is started using "await…

Peter
- 3
- 3
0
votes
0 answers
Realtime stdout/stderr from Dockerized Ubuntu bash session (async ssh with trio)
I need to ssh into a docker container (ubuntu/bash) and access stdout/stderr as it is emmitted (rather than wait for the entire command to complete then pick it up).
I found asyncssh which appears to be asyncio-based. GPT4 suggests:
import…

P i
- 29,020
- 36
- 159
- 267
0
votes
3 answers
trio.Event(): Which is “better”: setting and initializing a new Event or checking if someone is waiting for it beforehand?
import trio
work_available = trio.Event()
async def get_work():
while True:
work = check_for_work()
if not work:
await work_available.wait()
else:
return work
def add_work_to_pile(...):
...
if…

Robert Siemer
- 32,405
- 11
- 84
- 94
0
votes
1 answer
Python trio, Saving JSON under loop within
Currently, am receiving a dict within my rec function coming from the receiver channel.
async def rec(receiver):
with open('data.json', 'w', encoding='utf-8', buffering=1) as f:
f.write('[\n')
async with receiver:
…

αԋɱҽԃ αмєяιcαη
- 11,825
- 3
- 17
- 50