python-trio

How to combine streams in anyio?

How to combine streams in anyio? Question: How to iterate over multiple steams at once in anyio, interleaving the items as they appear? Let’s say, I want a simple equivalent of annotate-output. The simplest I could make is #!/usr/bin/env python3 import dataclasses from collections.abc import Sequence from typing import TypeVar import anyio import anyio.abc import …

Total answers: 1

Python, Trio async function upon needs

Python, Trio async function upon needs Question: 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 expired and …

Total answers: 1

Running trivial async code from sync in Python

Running trivial async code from sync in Python Question: 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 off the …

Total answers: 2

Proper way to cancel remaining trio nursery tasks inside fastAPI websocket?

Proper way to cancel remaining trio nursery tasks inside fastAPI websocket? Question: 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) …

Total answers: 1

What is the core difference between asyncio and trio?

What is the core difference between asyncio and trio? Question: 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 about …

Total answers: 1

In trio, how can I have a background task that lives as long as my object does?

In trio, how can I have a background task that lives as long as my object does? Question: 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 …

Total answers: 1