Skip to main content

All Questions

0 votes
2 answers
289 views

Is it safe to create asyncio event loop in one thread and run it in another thread while having ability to cancel it from outside the thread (python3)

I want to know if it's safe to create an asyncio event loop in one thread and run the loop in another while having the ability to cancel it from outside the thread in which the event loop is running. ...
Jishnu's user avatar
  • 130
0 votes
1 answer
70 views

Is there an issue if two asyncio tasks, one reads and one writes, uses one single websocket at the same time?

I have the following simplified code: import asyncio import websockets async def read_from_ws(websocket): async for message in websocket: print(f"Received message: {message}") ...
Viet Than's user avatar
  • 320
1 vote
1 answer
74 views

Keep a variable between two threads in python [duplicate]

I'm using python Fastapi. I am running an application that at one point launches a job to an external service. The service then sends a webhook with the job's status, a status I receive in an endpoint ...
Ingrid5's user avatar
  • 11
1 vote
0 answers
71 views

Why is my transferred data being written into disk out-of-order after passing a certain number of asynchronous tasks running?

So I have those two scripts that are meant to be used for extremely fast file transfers in local networks Receiver Script: import asyncio import logging import sys import time import aiofiles import ...
LuckyCoder3607's user avatar
1 vote
1 answer
205 views

AttributeError: 'function' object has no attribute 'submit' [duplicate]

I am using fastapi and uvicorn as my python server and whenever a user visits a route, I want to start a subprocess in the background. I used asyncio.create_task and loop.run_in_excutor in order to ...
Zaid's user avatar
  • 87
0 votes
1 answer
49 views

Running an async task in the background after others finished

I have X asynchronous tasks that are executed using asyncio.gather(), and they are created in a loop. Once these tasks are finished, I need to run a single asynchronous task to perform some actions. ...
Relys's user avatar
  • 65
2 votes
0 answers
135 views

Why don't threads close when using httpx in asynchronous functions?

I'm running python code (3.10.14) in jupyter notebook. However, when I run an asynchronous function (AsyncClient.get(...) from httpx v0.27.0) in the cell , I see that one of the threads is still alive ...
ojcio19 's user avatar
1 vote
1 answer
166 views

How do you use asyncio module with TWS API in python?

I am trying to use async threads with TWS API in the asyncio module. It seems I have it working but I just need to possibly gather threads in a main function so they all run on the same event loop? ...
Hayden's user avatar
  • 19
3 votes
1 answer
5k views

Using loop.run_in_executor to call sync functions from async ones

I have 3 functions: func_1, func_2, and func_3. I would like to run these asynchronously, so that I do not have to wait for func_1 to finish before func_2 starts executing. The problem is, that the ...
Datajack's user avatar
  • 210
-1 votes
1 answer
141 views

How do I create a multithreaded async server application with Python [closed]

for clarity i am using python3.10.9 The program i am trying to make consists of a ThreadPool and some type of async runtime environment. If a connection comes in on a listening socket, the async ...
userh897's user avatar
  • 271
1 vote
1 answer
724 views

call_soon_threadsafe never call the function if it is inside an async function

I am working with a third party library that will call a function I gave it from another thread at some random time. It can be modelled as a delayed function call in another thread. The function I ...
Jeffrey Chen's user avatar
  • 1,977
0 votes
1 answer
2k views

python run asyncio task in the background

I want to run asynio task in the background so that below code prints out 'b' once while printing out 'a' recursively. Instead it prints 'a' forever with no 'b'. It should cancel the task after 3 ...
tompal18's user avatar
  • 1,226
2 votes
1 answer
418 views

Not getting any response from the server in case of some requests with asyncio and aiohttp

I am trying to send asynchronous requests in python using asyncio and aiohttp. While I am trying to make multiple requests all at once and sending them all at once to the server I am getting back ...
Bilal Ahmed Karbelkar's user avatar
1 vote
1 answer
1k views

How to run a blocking task asynchronously with ProcessPoolExecutor and asyncio?

Im trying to run a blocking task asynchronously with ProcessPoolExecutor (It works with ThreadPoolExecutor but I need ProcessPoolExecutor for CPU-bound task). Here is my code : import asyncio import ...
Sabrebar's user avatar
  • 109
0 votes
1 answer
221 views

Are system calls ran on the same thread?

When using the multi-threaded approach to solve IO Bound problems in Python, this works by freeing the GIL. Let us suppose we have Thread1 which takes 10 seconds to read a file, during this 10 seconds ...
Joe's user avatar
  • 373

15 30 50 per page
1
2 3 4 5