7,940 questions
0
votes
1
answer
70
views
I have two simple Python functions with time.sleep and reading data so I/O-bound but I don't get expected behavior from threading and asyncio
Previously I had a question on an example of multiprocessing which you can see in the following link
I used a 2 workers pool to split a sum in a function with Python multiprocessing but the timing ...
1
vote
1
answer
52
views
how to make socket server propagate exceptions up to TaskGroup where they're started from?
How to make exceptions thrown from a socket server running in a task group task be propagated up to its parent TaskGroup? With given example, I'd expect to see the error raised from ...
3
votes
2
answers
73
views
Python asyncio.gather returning Future attached to differnt loop exception
I am using Python 3.13.2.
I am going through the Python asyncio tutorial here. At around 10:20 timestamp, the instructor shows an example of asyncio.gather with a coroutine accepting a Future.
Here is ...
Best practices
0
votes
2
replies
67
views
Python AsyncIO Graceful shutdown
No matter how much I search (or maybe I'm searching incorrectly), I can't find a decent way to terminate my tasks in Python AsyncIO.
I know what:
- I need to bind to signals (SIGINT, SIGTERM) using ...
Advice
1
vote
5
replies
146
views
How does Python differentiate between async function calls and actual I/O operations?
I understand that:
await some_async_function() doesn't yield control - it just calls the function synchronously
await some_io_function() DOES yield control to the event loop
But what's the actual ...
0
votes
1
answer
97
views
Parallelize asynchronous API calls in Python
I’m building a data ingestion pipeline in Python that collects data from a third-party REST API.
The API allows a maximum of 100 requests per minute, and I need to fetch data for tens of thousands of ...
1
vote
1
answer
101
views
Why are my asyncio HTTP requests not overlapping as expected for I/O?
I'm trying to make a bunch of HTTP GET requests to different endpoints of the same API. My understanding is that asyncio helps me manage concurrent I/O operations efficiently, meaning when one network ...
1
vote
0
answers
94
views
Python Asyncio: Timed out during opening handshake
I keep getting a timeout error which I can't currently explain. I'm new to networking in Python, but I can create and interact with example websocket code. For some reason the code below hits a ...
7
votes
2
answers
335
views
Why does multiprocess with "fork" fail under Python 3.14 but work in 3.13 (works only with "spawn" and "forkserver")?
The following code works fine on Python 3.13, but fails on Python 3.14 with a RuntimeError related to asyncio tasks.
If I switch the multiprocessing start method from "fork" to "spawn&...
-2
votes
1
answer
50
views
Weird errors while trying to connect to Mega.NZ from Python via https://pypi.org/project/mega.py/ [closed]
I'm trying to connect to Mega.NZ via module https://pypi.org/project/mega.py/ with this code:
#!/usr/bin/env python3
from mega import Mega
mega = Mega()
m = mega.login("my mail", "my ...
0
votes
1
answer
114
views
python REPL: is it possible to combine -i and -m asyncio?
I was trying to start the asyncio REPL (python -m asyncio) and to execute a script before starting the interactive REPL (python -i ./script.py). I tried re-ordering of options, the end-of-options ...
0
votes
2
answers
101
views
asyncio.run with SQLAlchemy asyncio sessions works only once, then raises "Future attached to a different loop" and "another operation is in progress"
I’m running into an issue when using asyncio.run together with SQLAlchemy (async) inside a Celery task.
When I call the function the first time, it works fine.
On the second call, I get:
RuntimeError: ...
2
votes
2
answers
150
views
How to safely check a multiprocessing.Event in an asyncio loop without blocking?
I'm working on an asynchronous server using asyncio, but I need to monitor a multiprocessing.Event (used to signal termination from another process) inside my async event loop. Here's the simplified ...
1
vote
2
answers
75
views
coroutine was never awaited with asyncio.TaskGroup
In the following code snippet, runner takes an optional semaphore. If this semaphore is provided, then all coroutines will be wrapped to handle entering the semaphore's context manager.
If I raise an ...
2
votes
1
answer
126
views
Threading or asyncio for serial communications?
I'm running some serial commands to test connected devices under test (DUTs), & we have a need to run these in parallel/concurrently to speed up our tests. I would like some feedback on which ...
0
votes
1
answer
231
views
How to run LlamaIndex ReAct agent with gpt-oss? Getting "SyntaxError: 'async for' outside async function"
I am trying to create a ReAct agent in LlamaIndex using a local gpt-oss-20b model.
I have successfully loaded my local model using HuggingFaceLLM from llama_index.llms.huggingface and it seems to be ...
0
votes
1
answer
70
views
How to determine which asyncio task a program is hanging in
I have a maddening bug that makes it look like my code is hanging inside an asyncio.sleep() call. ie.
while condition:
print("Before Sleep")
await asyncio.sleep(0)
print("...
0
votes
1
answer
572
views
Discord voice WebSocket 4006 "Session is no longer valid" error with Nextcord (classic prefix command)
I’m developing a Discord bot in Python using Nextcord, with classic prefix commands. I want the bot to join a voice channel when a user sends a command.
However, when running the voice join command, ...
0
votes
1
answer
97
views
asyncio.run() raise "RuntimeError: Event loop is closed" in a Jupyter Notebook
I'm trying to run an async function inside a Jupyter Notebook using asyncio.run() like this:
import asyncio
async def my_task():
await asyncio.sleep(1)
return "Done"
asyncio.run(...
0
votes
0
answers
131
views
Input audio from microphone not collected when audio is reproduced
I'm developing a simple real-time voice bot using the OpenAI real-time API, specifically integrating with Semantic Kernel. The code is written in an async manner, and it initially works well. However, ...
2
votes
1
answer
231
views
Using Asyncio for downloading big files: 10 times slower than threading
The goal is to download images from the URLs asynchronously.
Here is the code for threading, which works fine:
import requests
import threading
import os
import time
import concurrent.futures as ...
2
votes
0
answers
173
views
Unexpected Memory Leak in Python's asyncio When Using contextvars with Nested TaskGroups
I'm encountering a subtle memory leak in a Python 3.12 application using asyncio, specifically when combining contextvars with deeply nested TaskGroup structures. The issue only appears under high ...
3
votes
1
answer
76
views
How to handle an asyncio Python library and may be called both from CLI and a Jupyter Notebook?
So I have a custom library, packaged with setuptools. In essence, it is a library that sends a lot of tasks to an API in parallel, thus concurrency is used with asyncio. So far, everyone has been ...
0
votes
0
answers
81
views
How can I trigger CVE-2024-30251 (aiohttp multipart/form-data DoS) with a minimal POC script? [Need a simple concrete example]
I am trying to reproduce CVE-2024-30251, a denial-of-service vulnerability in aiohttp (Python async web framework) that affects versions prior to 3.9.4. According to the advisories, this vulnerability ...
0
votes
2
answers
100
views
Asyncio order of execution vs trio order of execution
I executed the same code with asyncio and trio more than ones. The order of execution for asyncio seemed to be preserved on every run but not with Trio.
Any particular reason that this happens?
...