7,933 questions
2
votes
1
answer
96
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
111
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
58
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
79
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
131
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
95
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
335
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
83
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
47
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 ...
0
votes
2
answers
113
views
How to write asyncio-based Python code that works both as a script and inside Jupyter
I’m developing a Python library that uses asyncio. When run as a regular Python script, everything works as expected.
However, the same library is also used inside Jupyter notebooks, where it fails ...
1
vote
1
answer
86
views
Why does asyncio.gather() not propagate cancellation immediately when one task awaits a blocking call?
I am trying to understand task cancellation semantics in asyncio, specifically when asyncio.gather() is used and one of the tasks indirectly blocks the event loop.
import asyncio
import time
async ...
0
votes
1
answer
156
views
ADK Google Gemini: "Session not found: default when" using InMemoryRunner with LlmAgent
I'm trying to use the Google ADK LLM agent (gemini-2.5-flash-lite) in a Flask project to check tests and review test content. I'm using InMemoryRunner and InMemorySessionService to run my agents.
Here'...
-3
votes
2
answers
171
views
"Event loop closed" with asyncio/asyncpg
I clearly have a fundamental misunderstanding of how async works. In Python 3.14, this snipped:
import asyncio
import asyncpg
def adapted_async():
conn = asyncio.run(asyncpg.connect(...
1
vote
2
answers
68
views
Is it okay to use a synchronous decorator on a FastAPI route?
I want to add a decorator on a FastAPI route like this:
/admin/verification.py
from functools import wraps
import json
def admin_required(admin_function):
@wraps(admin_function)
def ...
2
votes
2
answers
196
views
What causes memory leaks when using Python asyncio tasks in a long-running service?
I’m building a long-running background service in Python using asyncio, and I’m facing a memory usage issue that keeps growing over time. The service schedules multiple async tasks every few seconds, ...