All Questions
45 questions
0
votes
2
answers
95
views
Creating a stoppable background task in Python
I want to run some function in the background, but be able to shut it down at will. I tried a bunch of solutions, the most obvious of which is asyncio tasks:
# Data source
DataSource = Generator[int, ...
1
vote
1
answer
51
views
How to run dependence tasks concurrently with non-dependence ones, and tasks inside for loop?
I am learning asyncio and there is a problem of running a dependence task concurrently with non-dependence ones. So far I couldn't make it work. This is my code:
import asyncio
import random
def ...
0
votes
2
answers
329
views
When does coroutine in asyncio actually cedes the execution?
I am trying to do a deep dive into Python's asyncio module. I understand we need to await the coroutine to get their results and when we await any coroutine, the surrounding coroutine cedes its ...
0
votes
1
answer
542
views
ThreadPoolExecutor asyncio analogue?
I used to use concurrent.futures.ThreadPoolExecutor in my projects, running my synchronous functions in separate threads with it.
Nowadays I mostly use asynchronous code with asyncio, but I have a ...
5
votes
3
answers
191
views
Designing python code to execute concurrent requests by server for maximum requests
I am trying to write the below python script, where for I have 5 servers and each server can process at max 2 requests concurrently. I have a pool of 10 requests to processed. Each server picks 2 ...
0
votes
0
answers
162
views
Change threads to asyncio to make API calls simpler and faster
I wrote a script that's doing what I want but not the way I want to do it. Rather than copy it here, I'm writing an equivalent that's completely useless but illustrates the main concept. The script ...
0
votes
1
answer
175
views
Concurency with event loop (async/await) in Python
I'm a bit confused. Asyncio has single-threaded event loop. Every co-routine runs in it. If I have coroutine that doesn't have any await/yield, such co-routine should be atomic. Why I should ever ...
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
4k
views
Asyncio vs Threading in python [duplicate]
I have been using asyncio for a while together with multiprocessing and threading in python. But I'm not sure if i can see the diference between AsyncIO and threading in python.
Python is always ...
0
votes
2
answers
615
views
How to alternate between multiple async functions with "loop.run_until_complete()" in Python?
I'm trying to run 2 async functions test1() and test2() with loop.run_until_complete() alternately in Python as shown below:
import asyncio
async def test1():
for _ in range(3):
print(&...
0
votes
1
answer
381
views
Run async task in class that extends Threading - python
I've created a python class that extends threading and uses a library that runs asyncio tasks.
import threading
from app.food import recipes
class Mixer(threading.Thread):
def __init__(self):
...
3
votes
1
answer
835
views
Why does my process list show multiple threads when running aiohttp?
I'm currently using aiohttp in one of my projects which uses asyncio. After searching for reasons why I'm getting a high amount of memory usage I detected that aiohttp seem to create threads in the ...
0
votes
1
answer
354
views
Python async process getting executed in different orders
I have an async function that calls an async subprocess and later on execution, the same function performs a file read. After execution of the subprocess, the file should be generated, but when I run ...
0
votes
0
answers
56
views
Schedule or run threads at the same time
class Foo:
def __init__(self, data):
self.data = data
self.id = str(uuid.uuid4())
async def do_action(self):
........
........
async def main():
data = //...
1
vote
0
answers
30
views
Trying to understand asyncio with Python
I am trying to run some concurrent tasks with asyncio. Currently, i got the following example:
import asyncio
from time import sleep
from signal import SIGINT, SIGTERM, signal
async def f():
...