Trio is a Python package for async concurrency and I/O that's obsessed with usability and correctness
Questions tagged [python-trio]
87 questions
3
votes
1 answer
Proper way to cancel remaining trio nursery tasks inside fastAPI websocket?
I'm still quite new to websockets and I've been given a problem I'm having a hard time solving.
I need to build a websocket endpoint with FastAPI in which a group of tasks are run asynchronously (to do so I went with trio) with each task returning a…

Tom
- 571
- 2
- 11
- 29
3
votes
0 answers
React to ipywidget events while the cell is blocket in an `await` (using `%autoawait` magic)
I would like to wait to asynchronous jupyter widget events while the cell is blocked executing async code (thus, usually idle, waiting for I/O, utilising the %autowait magic). Unfortunately, the jupyter notebook does not seem to send any traitlet…

burnpanck
- 1,955
- 1
- 12
- 36
3
votes
1 answer
Use anyio.TaskGroup with fastapi.StreamingResponse
anyio is a part of starlette and, therefore, of FastAPI. I find it quite convenient to use its task groups to perform concurrent requests to external services outside of one of my API servers.
Also, I would like to stream out the results as soon as…

Oleksandr Fedorov
- 1,213
- 10
- 17
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,621
- 20
- 41
3
votes
1 answer
How to clean up connections after KeyboardInterrupt in python-trio
My class when is connected to the server should immediately send sign in string, afterwards when the session is over it should send out the sign out string and clean up the sockets. Below is my code.
import trio
class test:
_buffer = 8192
…

NarūnasK
- 4,564
- 8
- 50
- 76
3
votes
1 answer
Combining py.test and trio/curio
I would to combine pytest and trio (or curio, if that is any easier), i.e. write my test cases as coroutine functions. This is relatively easy to achieve by declaring a custom test runner in conftest.py:
@pytest.mark.tryfirst
def…

Nikratio
- 2,338
- 2
- 29
- 43
2
votes
0 answers
How to use events (Chrome-Developer-Tools) using Selenium with Python as a thread?
My current code is like that:
# Note: driver variable allready initialzed (Chrome)
import trio # async library that selenium uses
import requests
from PIL import Image
from io import BytesIO
def show_image(url):
try:
response =…

kaliiiiiiiii
- 925
- 1
- 2
- 21
2
votes
1 answer
Callback when tasks are added/removed in trio.Nursery
Question
Is there any official / Better approach to add callback on nursery's task add/remove, rather than wrapping the trio._core._run.GLOBAL_RUN_CONTEXT.runner.tasks set?
Details
With the purpose of studying the internals of trio.Nursery (and…

jupiterbjy
- 2,882
- 1
- 10
- 28
2
votes
1 answer
Use trio nursery as a generator for Sever Sent Events with FastAPI?
I'm trying to build a Server-Sent Events endpoint with FastAPI but I'm unsure if what I'm trying to accomplish is possible or how I would go about doing it.
Introduction to the problem
Basically let's say I have a run_task(limit, task) async…

Tom
- 571
- 2
- 11
- 29
2
votes
1 answer
How Can I Prevent an Exception Raised By a Child Taking Down the Whole Nursery
Consider the following code:
import trio
async def broken_fn():
await trio.sleep(4)
print(1 / 0)
async def worker_fn():
while True:
print("working...")
await trio.sleep(1)
async def main():
async with…

Wildebeest
- 23
- 3
2
votes
2 answers
Python and Trio, where producers are consumers, how to exit gracefully when the job is done?
I'm trying to make a simple web crawler using trio an asks. I use nursery to start a couple of crawlers at once, and memory channel to maintain a list of urls to visit.
Each crawler receives clones of both ends of that channel, so they can grab a…

Paweł Lis
- 125
- 8
2
votes
1 answer
Problem in running Trio with Kivy and Socket.io
Currently, I'm trying to run Kivy, Socket.io as coroutine of Trio. It seems that Kivy UI showing the blank screen and seem to be unresponsive. Earlier, Kivy was working with Trio, after socket.io added, it became unresponsive. Provided Sample code…

Sanjiv
- 813
- 6
- 13
2
votes
1 answer
How to gather results and using limit with parent child functions
What I'm trying to achieve is something along the lines of spawning multiple parents and with each parent do some work and then spawn a few childs to check for other things and grab those results in the parent to do further work.
I was also trying…

Zigb
- 23
- 2
2
votes
1 answer
"asks" async https client: 'SSLEOFERROR on connect attempt to server with self-signed cert --WARNING: handtyped stack trace--
See updates
I'm trying to send request to a web server with a self-signed certificate (works fine on sites that aren't self-signed) and i keep getting the error:
SSLEOFERROR EOF occurred in violation of protocol
Conversely when using requests, the…

Info5ek
- 1,227
- 4
- 17
- 25
2
votes
2 answers
how to structure beginning and ending synchronous calls using trio?
My ask is for structured trio pseudo-code (actual trio function-calls, but dummy worker-does-work-here fill-in) so I can understand and try out good flow-control practices for switching between synchronous and asynchronous processes.
I want to do…

bija
- 83
- 3