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
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
  • 3,528
  • 5
  • 33
  • 65
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,138
  • 2
  • 25
  • 40
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
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,555
  • 2
  • 13
  • 20
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,089
  • 3
  • 14
  • 24
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
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…
2
votes
1 answer

How to compact code that chooses how many concurrent tasks are made based on input?

I have a scrapper 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
  • 454
  • 6
  • 24
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,138
  • 2
  • 25
  • 40
1
vote
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
  • 55
  • 5
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
  • 6,565
  • 1
  • 27
  • 42
1
vote
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
  • 653
  • 4
  • 12
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
  • 454
  • 6
  • 24
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
  • 454
  • 6
  • 24