7,935 questions
Best practices
0
votes
3
replies
95
views
__await__: may it be called several times and then wait again?
For iterators, there is a clear protocol: once they are exhausted, they remain exhausted.
It is not allowed to create an iterator whose __next__() raises StopIteration and, called once again, return a ...
-1
votes
1
answer
174
views
What does awaiting an object of a user-defined class do?
The Python documentation says:
await is a Python keyword that’s commonly used in one of two different ways:
await task
await coroutine
In a crucial way, the behavior of await depends on the type of ...
1
vote
1
answer
219
views
Why does Python asyncio performance decrease when creating too many small tasks?
I'm experimenting with Python asyncio and noticed that performance becomes worse when I create a very large number of very small async tasks.
import asyncio
import time
async def tiny_task():
...
2
votes
0
answers
100
views
grpc.aio + uvloop raises BlockingIOError: [Errno 35] Resource temporarily unavailable
I migrated a Python service from sync grpcio calls wrapped in asyncio.to_thread(...) to native grpc.aio to reduce per-call latency, but after the switch I started seeing this error repeatedly in the ...
Advice
0
votes
7
replies
117
views
How to Schedule Weekly Asyncio Tasks
Currently working on a bot for Stoat (a Discord alternative) and was working with asyncio to hopefully have tasks done at a specific time each day or each week. For example, one would execute my ...
Advice
0
votes
2
replies
75
views
What is the best way for a django application to query a remote noise meter and update the live data in a users browser?
As the title implies, I am attempting to write a Django application to query noise meters remotely and display the real time information in a web page. Currently I am able to display live data in the ...
1
vote
2
answers
116
views
One aync lock call or multiple async lock calls, what is better and safer in Python?
I trying to make ratelimiter for users in aiogram bot with middlware, now I created class for requests and class for ratelimiter, where reuqest are. My problem is what is better for performance and ...
0
votes
2
answers
74
views
Why can't I continue to submit jobs to a async io loop that has been started with run forever
I am trying to model a system that uses asyncio and an event loop. I find that if I create an event loop, and start it with run forever it will not process new tasks, unless it has an unfinished ...
3
votes
1
answer
88
views
How can I use asyncio in a script that I also run as a Jupyter notebook?
I often create Jupyter notebooks as plain .py files with # %% cell delimiters, like this:
# %%
import polars as pl
import numpy as np
# %%
df = pl.read_parquet('my_cool.parquet')
...
I can then run ...
Best practices
0
votes
0
replies
36
views
httpx.AsyncClient - single or multiple pools per domain
I am creating an async FastAPI service that trigger models via post requests.
Each model has a different domain.
It should support high throughput and low latency.
What is the best way managing it? ...
Best practices
0
votes
0
replies
73
views
waiting for asyncio.Task completion, propagate exceptions
For asyncio workloads there's this convenience function that executes passed list of asyncio.Tasks until either
a timeout is hit;
first Task raises an exception; or
all tasks succeed
First two ...
0
votes
1
answer
74
views
Why does asyncio.gather with pandas DataFrame rows not run concurrently?
I'm processing a large pandas DataFrame (500k rows) where each row requires an HTTP request. I switched from requests to aiohttp + asyncio expecting a significant speedup, but the async version runs ...
2
votes
1
answer
115
views
What are the advantages/disadvantages of starting a new `ThreadPoolExecutor` when doing `loop.run_in_executor`?
Looking at the documentation for Event Loop, there is this example:
import asyncio
import concurrent.futures
def blocking_io():
# File operations (such as logging) can block the
# event loop: ...
Best practices
1
vote
3
replies
168
views
FastAPI high-load login: how to handle bcrypt/argon2 hashing without blocking and scaling limits?
I’m working on a high-load async web application using FastAPI and I have a question about implementing login/registration logic with password hashing.
Problem
As we know, password hashing (e.g. with ...
1
vote
1
answer
81
views
Combining asyncio and multiprocessing queues
I have a task where I have to fetch a lot of files from a database (I/O-bound) and process each of them (CPU-bound). I thought of using a producer-consumer pattern, where fetch workers (producers) ...