7,935 questions
1
vote
1
answer
40
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
66
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
71
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
22
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
59
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
58
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
112
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
131
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
64
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) ...
1
vote
1
answer
131
views
Py-cord RuntimeError: There is no current event loop in thread 'MainThread'
I've returned to a bot I created using the py-cord module several months ago, on a new device where I've reinstalled py-cord. The bot loaded fine when I was originally working on it, but now when I ...
5
votes
1
answer
155
views
Why does python 3.13.8 raise an IndentationError when running in asyncio mode on the terminal
Using Python >=3.13.0 (tried 3.11.14, 3.12.10, 3.13.0, 3.13.8 and 3.14.0a5), when I try to run the terminal in async mode, it throws an IndentationError when I try to start an async with code block:...
1
vote
1
answer
121
views
asyncio.Queue - any benefit in async put with maxsize?
I have a sync call function that puts task in an asyncio.Queue so it can be processed by an async worker. Currently, I have something like this:
import asyncio
import os
import sys
queue = asyncio....
2
votes
1
answer
341
views
Python logging error: Unexpected error occurred: cannot schedule new futures after shutdown
I see the errors when using this custom HttpHandler in my logger. Error deals with this handler because there are no error, when using another handlers.
I see error only in K8S. Checked that POD ...
4
votes
1
answer
87
views
Why py_mcws.WsClient don't run with my asyncio event_loop?
I want to create a window program that connects a Minecraft world to a local websocket. It works fine in the Thonny IDE and I can run everything smoothly, but when I try to start it via Bash, it ...
0
votes
0
answers
53
views
Global AsyncClient Reuse Best Practices
I'm wondering what the best practice for a global httpx GlobalClient is in Python 3.14. generally it's best to have a single global event loop, but what if I need more parallelism or to not block with ...