Linked Questions
21 questions linked to/from Error "RuntimeError: This event loop is already running" in Python
225 votes
14 answers
357k views
Asynchronous method call in Python?
I was wondering if there's any library for asynchronous method calls in Python. It would be great if you could do something like @async def longComputation(): <code> token = longComputation(...
40 votes
6 answers
69k views
RuntimeError: Timeout context manager should be used inside a task
Background: I am hosting a flask server alongside a discord client The flask server just needs to pass on messages from the client to discord and from messages from discord to the client. I am ...
53 votes
3 answers
9k views
Duplication of code for synchronous and asynchronous implementations
When implementing classes that have uses in both synchronous and asynchronous applications, I find myself maintaining virtually identical code for both use cases. Just as an example, consider: from ...
11 votes
1 answer
16k views
asyncio: RuntimeError this event loop is already running
This seems like a common problem. See for example: Error "RuntimeError: This event loop is already running" in Python But in my case, I'm only starting the event loop once, at least as far ...
9 votes
1 answer
9k views
async 'read_csv' of several data frames in pandas - why isn't it faster
I want to create a code that reads several pandas data frames asynchronously, for example from a CSV file (or from a database) I wrote the following code, assuming that it should import the two data ...
2 votes
3 answers
5k views
How to make pydantic await on a async property (tortoise-orm's reverse ForeignKey)?
(MRE in the bottom of the question) In tortoise-orm, we have to await on reverse ForeignKey field as such: comments = await Post.get(id=id).comments But in fastapi, when returning a Post instance, ...
2 votes
1 answer
3k views
Gremlin Python Cannot run the event loop
I am running Gremlin Python. Firstly, I did the installation in my local machine following these instructions here then I ran the code of this website here, but I got the following error at this bit: ...
1 vote
1 answer
3k views
asyncio.get_event_loop() fails when following asyncio.run()
I'm trying to find a solution to call async function in a Synchronous context. And following is my references: Python call callback after async function is done When using asyncio, how do you allow ...
3 votes
1 answer
2k views
How to choose asynchronous or synchronous method variants in python?
Let's assume I have a class that is used to perform I/O operations: class CommunicationStack: def __init__(self, socket): self.socket = socket def sync_get_data(self): ... ...
0 votes
2 answers
2k views
Using the aioftp with asyncio for downloading files to local repository
recently I have been studying the application of Python's Package "aioftp" in order to download asynchronously some data from a remote server. So far, I have had no success in my efforts. ...
0 votes
1 answer
2k views
Python 3.9: How to correctly await a lock in non-async function
TL;DR: Q: How to lock protect a shared resource from a sync function in py39? Sorry if this was already answered - I just couldn't find it easily. I'm struggling how to correctly await a lock when ...
0 votes
6 answers
2k views
IB_insync - Sanic error after one successful order preventing any further orders
I'm writing an API using ib_insync, Sanic and ngrok to forward webhook signals from Tradingview onto Interactive Brokers. It works on only the first attempt and the following error is thrown ...
0 votes
1 answer
977 views
I made a loop for my bot but it won't run [duplicate]
I am making a discord bot using discord.py and I am using an event loop for my borrow command, but when I run it it gives me a bunch of error codes. The error code said that the loop is already ...
4 votes
1 answer
555 views
*Why* isn't run_until_complete re-entrant. How to incrementally port to async without threads?
Let's say I'm tasked with migrating a Flask project to an async Python webserver. I'm looking to for patterns to minimize the amount of work here. It appears to me, more or less, impossible to port ...
1 vote
0 answers
2k views
Unable to start ARQ worker in FastAPI
I am unable to startup an arq worker in FastAPI even though i was able to create a redis pool and submit a task, but without an active worker, the task would not be executed. I called the Worker class ...