Questions tagged [python-anyio]

A wrapper for asynchronous I/O libraries trio and asyncio. Use this tag with questions about programming with anyio in Python.

16 questions
4
votes
2 answers

How do I run python asynchronous script with poetry tool script?

I want to run python asynchronous script with poetry tool script. Could you please help? In pyproject.toml, I added like this. [tool.poetry.scripts] clear_data = "clear_data.clear_data:main" In my python file, I wrote like this. from anyio import…
Julia
  • 51
  • 4
3
votes
1 answer

FastAPI `run_in_threadpool` getting stuck

I have implemented all my routes using async. And have followed all guidelines from the FastAPI documentation. Every route has multiple DB calls, which does not have async support, so they are normal function like this def db_fetch(query): # I…
Irfanuddin
  • 2,295
  • 1
  • 15
  • 29
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
2
votes
0 answers

Exception somewhere in the httpx/httpcore entrails

I've a scraping engine which uses any proxy list, and retries in case the proxy doesn't work. So there are plenty of proxies that timeout, have connection refused, bad certificates etc. After I switched to httpx from aiohttp I have plenty of…
aikipooh
  • 137
  • 1
  • 19
1
vote
2 answers

Wrapping a polling-based asynchronous API as an Awaitable

Consider some library with an interface like this: RemoteTask.start() RemoteTask.cancel() RemoteTask.get_id() RemoteTask.get_result() RemoteTask.is_done() For example, concurrent.futures.Future implements an API like this, but I don't want to…
shadowtalker
  • 12,529
  • 3
  • 53
  • 96
1
vote
1 answer

Python, Trio async function upon needs

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…
1
vote
1 answer

FastAPI Async Test Failing With Middleware

I want to add middleware to my FastAPI instance in order to do some custom exception handling (logging etc) but once added I receive the following error on my pytest endpoint healthcheck: self =
Sylver11
  • 129
  • 1
  • 8
1
vote
1 answer

Why are there up to 40 tasks running on anyio?

import logging import time from datetime import datetime import anyio import numpy as np from anyio.streams.memory import MemoryObjectReceiveStream as rstream from anyio.streams.memory import MemoryObjectSendStream as…
phi friday
  • 191
  • 4
1
vote
0 answers

anyio.sleep() timing inconsistencies at small sleep times between asyncio and trio

python 3.9.5 (anyio, asyncio, trio) windows 10 I am attempting to use anyio.sleep() to limit how fast my main app loop is running, in addition to having another async loop in a class running as a task. I've noticed when I decrease the sleep period…
josh
  • 11
  • 1
0
votes
0 answers

Pytest indirect parametrization using anyio

Pytest offers a way to parametrize fixture just before running test function (documentation) But I am trying to write async tests using AnyIO Below is my modified code from example import pytest @pytest.fixture(scope="session") def anyio_backend()…
0
votes
1 answer

Asyncio async_wrap to convert sync functions to async in python. How does it work?

I huge chunk of legacy sync code ( a huge function which calls other sync functions, includes sync http API calls with requests library, and so on ). This function is run as a part of a Queue worker (picks up tasks from the queue and executes this…
D.B.K
  • 410
  • 2
  • 15
0
votes
0 answers

Is it ok to use anyio.sleep_forever() to prevent a process from exiting?

In my case I am registering consumers on aio-pika: async def on_message(message: AbstractIncomingMessage) -> None: async with message.process(): print(f" [x] Received message {message!r}") print(f" Message body is:…
Joaquim
  • 111
  • 1
  • 10
0
votes
1 answer

Asyncio as_completed in AnyIO

How can I implement the functionality of asyncio as_completed on anyio? I have a messagebus that pickup an user command and directs it to appropriate handler. That may generate a new domain event that should be picked up by the bus too. Using…
Joaquim
  • 111
  • 1
  • 10
0
votes
0 answers

Selecting / asynchronous choice: between two async coroutines

I'd like to implement a CSP procedure in Python alternating between consuming items from a networked queue and doing health checks on the main execution fiber. async def lifecycle_consumer(config: LifecycleConfig, pool: AsyncConnectionPool, redis:…
Henrik
  • 9,714
  • 5
  • 53
  • 87
0
votes
1 answer

Make multiprocessing.Queue accessible from asyncio

Given a multiprocessing.Queue that is filled from different Python threads, created via ThreadPoolExecutor.submit(...). How to access that Queue with asyncio / Trio / Anyio in a safe manner (context FastAPI) and reliable manner? I am aware of Janus…
1
2