All Questions
62 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. ...
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}")
...
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 ...
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 ...
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 ...
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. ...
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 ...
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? ...
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 ...
-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 ...
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 ...
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 ...
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 ...
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 ...
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 ...