Skip to main content

All Questions

0 votes
1 answer
23 views

Asyncio: read new data from process stdout without blocking monitoring task

I write asynchronous process manager, and up till now I came up with this: import asyncio class AsyncLocalProcessManager: def __init__(self): self.process = None async def submit(...
291 votes
10 answers
393k views

Simplest async/await example possible in Python

I've read many examples, blog posts, questions/answers about asyncio / async / await in Python 3.5+, many were complex, the simplest I found was probably this one. Still it uses ensure_future, and for ...
1 vote
1 answer
4k views

Pausing Python asyncio coroutines

As my project heavily relies on asynchronous network I/O, I always have to expect some weird network error to occur: whether it is the service I'm connecting to having an API outage, or my own server ...
2 votes
2 answers
3k views

asyncio - wait for each task in a dynamic list to finish or be cancelled

I have a list of asyncio tasks: [task1, task2, task3]. And each task can append more tasks to this list, e.g., task3 might append task4. How can I wait for all tasks in this dynamic list to finish or ...
10 votes
1 answer
8k views

How to catch exceptions in a python run_in_executor method call

How can i raise the exception in the run_long_thing() function called with the run_in_executor? It looks like it is being swallowed. I don't need the result of the function in the blocking code. It is ...
4 votes
1 answer
9k views

"RuntimeError: no running event loop" with "asyncio.get_running_loop()" in Python

I'm trying to run the code below with asyncio.get_running_loop(): import asyncio async def test(): for _ in range(3): print("Test") await asyncio.sleep(1) loop = ...
0 votes
2 answers
287 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. ...
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 ...
153 votes
11 answers
111k views

How to limit concurrency with Python asyncio?

Let's assume we have a bunch of links to download and each of the link may take a different amount of time to download. And I'm allowed to download using utmost 3 connections only. Now, I want to ...
-2 votes
1 answer
275 views

Running Python 3.12 asyncio tasks in parallel

What specifically needs to change in the Python 3.12 code below in order for each and every one of the calls to the write_to_file(linesBuffer) function to run in parallel instead of running ...
9 votes
2 answers
5k views

How to write your own async-awaitable coroutine function in Python?

I'm trying to write my own awaiatbale function which could be used in an asyncio loop like asyncio.sleep() method or something like these pre-awaitable implemented methods. Here is what I've done so ...
26 votes
1 answer
24k views

asyncpg - cannot perform operation: another operation is in progress

I am attempting to resolve the following error: asyncpg.exceptions._base.InterfaceError: cannot perform operation: another operation is in progress Here is the full traceback: Traceback (most recent ...
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}") ...
60 votes
6 answers
175k views

Call async function from sync function, while the synchronous function continues : Python

After perusing many docs on AsyncIO and articles I still could not find an answer to this : Run a function asynchronously (without using a thread) and also ensure the function calling this async ...
0 votes
1 answer
72 views

Stripe Python AttributeError: 'coroutine' object has no attribute 'auto_paging_iter'

An example in the Stripe Python library doesn't seem to work. The README says: # .auto_paging_iter() implements both AsyncIterable and Iterable async for c in await stripe.Customer.list_async()....

15 30 50 per page
1
2 3 4 5
20