Questions tagged [python-asyncio]

This tag is to be used for the asyncio Python package which provides mechanisms for writing single-threaded concurrent code. The asyncio package provides asynchronous I/O, event loop, coroutines and tasks beginning with Python 3.4.

Filter by
Sorted by
Tagged with
-2 votes
1 answer
30 views

Python - How to use the function's old result while waiting for its new result

Let's say I have 2 functions like this: Function 1: To Calculate a. And it takes 5 hours to return the result of a for each calculation. def Calculate_a (x,y,z,t) Do_somthing_to_calculate_a ...
Minh's user avatar
  • 9
-1 votes
1 answer
47 views

How to use the function's old result while waiting for its new result in Python [closed]

Let's say I have 2 functions like this: Function 1: To Calculate a. And it takes 5 hours to return the result of a for each calculation. def Calculate_a (x,y,z,t) Do_somthing_to_calculate_a ...
Minh's user avatar
  • 9
-1 votes
0 answers
34 views

Why does my if condition/function does not work properly?

I am trying to build a system where the messages recieved from telegram telethon library are filtered out and put in to a database when it the message contains certain information, but for some reason ...
onat dicleli's user avatar
0 votes
0 answers
28 views

Celery instead of Async views with asyncio in django

I am new to django! (So basically i am seeking suggestions for this approach). In my project i had so many views and each view had atleast 1 database i/o and as all my views are synchronous i find ...
varun_k_21's user avatar
1 vote
1 answer
23 views

Running a long, blocking, python script on_message with discord.py

I'm creating my first Discord bot in Python (hosted locally, for security), and the main function is meant to be running a cheat-detection script when asked. The issue is that cheat-detection script ...
brian gilbert's user avatar
0 votes
1 answer
23 views

Program using Asyncio with queue ends before consumer finishes

I have the following producer pattern where I obtain data from a source, place it in queue, then consume it and write it to a CSV file. However, the program seems to end early because my tasks are all ...
Coldchain9's user avatar
  • 1,497
0 votes
0 answers
39 views

Why is `to_thread` faster than `create_task` in python asyncio?

I have a blocking function that calls an REST endpoint and returns some result. Let's simulate that as below: import random, time, asyncio def test_func(x): time.sleep(2*random.random()) ...
qkhhly's user avatar
  • 1,160
1 vote
0 answers
34 views

MissingGreenlet: greenlet_spawn has not been called; can't call await_only() here. Was IO attempted in an unexpected place?

I am trying to perform alembic migrations but receiving the error 'sqlalchemy.exc.MissingGreenlet: greenlet_spawn has not been called; can't call await_only() here. Was IO attempted in an unexpected ...
Nastassia's user avatar
0 votes
0 answers
29 views

Timeout context not inside a Task [Python 3.x]

I am not really familiar with async functions but I have worked in creating discord bots in the past and know some basics here and there to make it work. I am currently building a React based front ...
code-wolf-byte's user avatar
0 votes
0 answers
25 views

How to use adlfs (ffspec) and pyarrow/pandas to download multiple blobs (read_parquet) concurrently with column projection and row filtering

I want to exploit pyarrow, ffspec and its Azure FS implementation adlfs in order to download multiple files in parallel. By parallel I mean that the actual IO-bound operation should exploit async/...
LucaM's user avatar
  • 57
0 votes
2 answers
54 views

Are there any ways to actually stop awaited long-running asyncio Task?

If there is a long-running background task, cancel() method does not work as I expected (does not work at all). And I cannot find a way to actually stop the task, is that even possible or am I missing ...
Shpinks's user avatar
  • 21
1 vote
1 answer
25 views

How to make an asynchronous principle of task execution from a task generator?

I have a problem, do you have any ideas for a solution? You need to add asynchronous tasks to the event loop without waiting for them to be completed (using await is not an option, otherwise there is ...
aero.exe's user avatar
0 votes
2 answers
62 views

python async with timer and endless loop

I have found two parts of code here for my planned project. The first with two timers ... class Timer: def __init__(self, interval, first_immediately, timer_name, context, callback): self....
Kaloschke's user avatar
0 votes
0 answers
28 views

exit tkinter gui python program when click pystray menu build with asyncio and fastapi

minimal code import sys import threading from fastapi import FastAPI from fastapi.responses import FileResponse from tkinter import * from fastapi.staticfiles import StaticFiles from fastapi....
edwin_uestc's user avatar
0 votes
0 answers
6 views

python asyncio echo server with prompt for additional message

I have created a small echo server using python asyncio which support multiple client connections. Now I would like the option of adding some way for the server to have a prompt where I can send ...
tbolind's user avatar
0 votes
0 answers
18 views

Running flask and python-telegram-bot (asyncio) in the same process

I am trying to initialize Flask and python-telegram-bot in the same process in Python 3.11. But the problem is that flask app.run() is blocking and python-telegram-bot uses asyncio. Now, this is the ...
lpares12's user avatar
  • 3,664
0 votes
1 answer
24 views

Running a background task with python asyncio

I am building a websocket server in which I want to have a background task that receives messages from SQS and sends them to client while not blocking rest of the events. But I keep getting this error,...
nycelia's user avatar
0 votes
1 answer
41 views

How to use websockets.broadcast() in while True loop

In this function, I want to get video frames and predict them, then broadcast predicted result to all subscribers, but when I run this function, clients can't receive result. Because code don't return ...
Ian Shih's user avatar
0 votes
0 answers
18 views

Python Asyncio StreamReader not cooperating with transport

I need to update code that relied on asyncio on Server side but no asyncio on the client side, only socket.socket() (and it worked). When I try to update client side to use asyncio StreamReader&...
annanananan's user avatar
0 votes
0 answers
27 views

Mediapipe Pose Estimator with Multiprocessing hanging with when used in a Docker container

I am trying to run mediapipe pose estimator inference in a docker container, multiprocessing.Process(). My scripts are connected to a Google PubSub service, reading messages containing images and then ...
Soogey's user avatar
  • 1
0 votes
1 answer
17 views

Python Tkinter: Sharing an asyncio event loop with Telemetrix-AIO

I'm using the Python Telemetrix library for controlling an ESP32. I've got a Tkinter application with an interface, and I'd like to connect and disconnect while the application is running so I can ...
Lokno's user avatar
  • 594
0 votes
0 answers
44 views

Multiple large requests using aiohttp

I need to send a large number (approximately 50) of HTTP POST requests, each with a size of around 5 MB. I use the asyncio.gather function to wait for the responses from these requests. However, the ...
Bala's user avatar
  • 1,129
0 votes
1 answer
32 views

How to properly close gather tasks if some of them take too long

I have code that looks like async def watch_task1(): while not stop: await client.ws.get_data() async def watch_task2(): while not stop: await client.ws.get_news() async def ...
Nicolas Rey's user avatar
0 votes
1 answer
47 views

How to run CPU bound async function in separate thread with asyncio.to_thread?

I'm making multiple calls to a 3rd party lib using asyncio tasks, wrapped in a function run_task, which is CPU intensive. I tried using asyncio.to_thread to run it in a separate thread but I am ...
indi qiqi's user avatar
0 votes
0 answers
19 views

Adding a cron job to cron_jobs with custom time

I want to create cron jobs for specific days of the week, hours, and minutes entered by the user. Here's my scheduler: from aiogram import Bot from src.bot.bot import pool_settings from src.config ...
Mabarik667f's user avatar
-1 votes
1 answer
47 views

async with bot: AttributeError: __aenter__

I've got a following error when running my code: File "C:\discord bot\main.py", line 19, in <module> asyncio.run(main()) File "C:\Users\punk102rus\AppData\Local\Programs\...
Ruslan's user avatar
  • 1
0 votes
1 answer
49 views

Python Asyncio - wait for one specific background task to finish before starting the next

I have an app which collects data in batches. Every time it's done collecting one batch, it saves the data. In order to speed things up, I've been using asyncio so that it can continue collecting data ...
BENJAMIN GILBERT's user avatar
0 votes
0 answers
48 views

Is there a way to return values using a TaskPool when making a large number of HTTP requests with asyncio/aiohttp?

This question is related to this one: perform-large-numbers-of-http-requests-asyncronously-n-at-a-time The problem is that I want to make a large amount of requests, about 500.000, each request get a ...
Ulrabab's user avatar
0 votes
0 answers
24 views

Async calls made to openai endpoint from .py file is taking longer than the time taken by same async calls from notebook

I'm trying to speeden up multiple openai chat completion api calls by calling them asynchronously. While this improvement is visible in jupyter notebook, but when the same code is run in a .py file it ...
learner123's user avatar
1 vote
1 answer
42 views

How to write a custom socket server correctly with asyncio?

Python 2 has an implemented class with asyncore.dispatcher I need to implement the same in Python 3. class Server(asyncore.dispatcher): def __init__(self, host, port, socketMap=None): ...
test_celery's user avatar
0 votes
1 answer
40 views

Issues with catching exceptions in a ThreadPoolExecutor

I have written the following class: class AsyncPillow: def __init__(self, FUNC: Callable, ARGS: tuple, POOL: ThreadPoolExecutor = None): self.FUNC = FUNC self.ARGS = ARGS ...
Fluxx's user avatar
  • 15
0 votes
0 answers
39 views

Precise timing in Python in a multithreaded enviornment

I am trying to replay a log file of CAN messages onto a virtual bus in Python. The log file contains a list of timestamped messages, and I want to keep the same timing of those messages when I send ...
Muhammad Yojer's user avatar
3 votes
1 answer
134 views

Asyncio BufferedProtocol doesn't do what it says in the documentation (doesn't avoid unnecessary copying)

According to the documentation: "BufferedProtocol implementations allow explicit manual allocation and control of the receive buffer. Event loops can then use the buffer provided by the protocol ...
IHaveAName's user avatar
3 votes
1 answer
117 views

Deadlock with asyncio.Semaphore

I have asyncio code that sometimes freezes in a deadlock, which should not be possible in my opinion. As reality always wins over theory, I must obviously be missing something. Can somebody spot a ...
Achim's user avatar
  • 15.5k
-3 votes
0 answers
66 views

Deleting a channel if it remains without users. Disnake, Discord.py

How to make a channel deleted after some time after there are no users left on it, but if someone comes to this channel, the timer will disappear or resume if there is no one on this channel? You can ...
Xalwer's user avatar
  • 1
0 votes
0 answers
28 views

asyncio: RuntimeError: no running event loop while running widgets

I try to show widget with two buttons (in file wait_action.py): from ipywidgets import Button, HBox from IPython.display import clear_output import asyncio def wait_for_change(...
Любовь Пономарева's user avatar
0 votes
1 answer
38 views

What is the proper way to start bunch of coroutines in loop using python asyncio.Semaphore?

I want to make a function, which will start bunch of coroutines, and wait for all of them to get done, by using asyncio Semaphore class. After processing this bunch of coroutines, I want to setup a ...
svat_di's user avatar
0 votes
1 answer
119 views

Getting asyncio.run() cannot be called from a running event loop

I have a python application which is running inside a uvicorn server. I have created a Pub/sub subscriber and trying to enable it from my main.py. I am using a streaming-pull subscription. Now, my ...
Sumit Desai's user avatar
  • 1,558
0 votes
0 answers
12 views

Why do I get a single connection sharing error when opening multiple connections in one pool (in unittest)?

It throw asyncpg.exceptions._base.InterfaceError: cannot perform operation: another operation is in progress I use an asyncpg, my code: in the test import unittest from models.create import ...
Alex's user avatar
  • 1
0 votes
2 answers
49 views

Websocket how to receive two request chatgpt at the sametime

I have a websocket (in Django) to receive request from client (reactjs). The request calls chatgpt api to stream its response to client. class GPTAPIConsumer(AsyncWebsocketConsumer): async def ...
Trong Lam Phan's user avatar
2 votes
2 answers
52 views

asyncio: how to handle exceptions

I'm using asyncio.gather() to run concurrently two coroutines. They should run forever, so if one of them returns (correctly or with an exception) I'd like to know. If I use try/except for asyncio....
pozzugno's user avatar
  • 806
0 votes
0 answers
63 views

Why is Synchronous SQLAlchemy Session Faster than Asynchronous in FastAPI

I am working with two versions of a FastAPI application: one using an asynchronous connection to a SQLAlchemy database and the other using a synchronous connection. Surprisingly, I'm observing that ...
ItayDar's user avatar
0 votes
0 answers
22 views

Calling a coroutine within a coroutine while there is an event loop running in the bg

I built a coro function within a pyscript tag that outputs a location of the space station using folium to the web from pyodide.http import pyfetch import asyncio import folium ...
TakoTatsuOji's user avatar
1 vote
0 answers
58 views

asyncio requests (aiohttp, aioftp, etc) in a class-based design

I am trying to move my codebase over to asyncio and aiohttp, aioftp, etc. I've been led to believe that the clients should be reused for multiple requests instead of opening a new one each time. For ...
S. B.'s user avatar
  • 73
2 votes
1 answer
78 views

Some of my coroutines are not (always) starting

I am working with Langchain and FastApi. Basically I am creating a StreamingResponse, which streams back JSON diffs. The diffs are created by comparing a JSON document to its previous version. The ...
darkie7's user avatar
  • 21
0 votes
0 answers
31 views

Telegram Bot - Why cant i receive any updates? api connecting ok

im trying to create a script to monitor a telegram channel and forward messages that meet a set criteria to my private channel. I have updated all admin accesses etc in the private, it is succesfully ...
user22949708's user avatar
0 votes
0 answers
32 views

Streamlit and asyncio: how to refresh UI

I run this code below which requests data from an API async and sets st.session_state variables, however the UI does not update until I click some random buttons or perform some actions. How to force ...
OlgaPp's user avatar
  • 180
0 votes
0 answers
41 views

How to manage a CancelledError in an Event loop with asyncio and python?

I am trying to use a python file to handle all requests sent by a bot to a server via API. According to their documentation, the use of asyncio is recommended. Here is my code below : import asyncio ...
Pooki_'s user avatar
  • 1
-1 votes
0 answers
77 views

Critique request: Implementing Litestar 2.0 with other concurrent processes sharing access to a data repository object

I’m rewriting my app and I would like to get feedback on my new design as most of the concepts are novel to me. The app is a backend running 3 concurrent processes all accessing the same data ...
Mauricio Vidal's user avatar
0 votes
2 answers
98 views

asyncio.gather not working as expected within FastApi [duplicate]

I have a FastApi app running with uvicorn for my local dev: uvicorn server.app:fapi --reload --host 0.0.0.0 --port 80 I would like to have have 3 couritines running at the same time, but it seems ...
Manuel Simões's user avatar

1
2 3 4 5
147