Linked Questions
11 questions linked to/from How to call a async function from a synchronized code Python
6 votes
1 answer
20k views
How to run an async function inside a regular function? [duplicate]
This is for a discord bot I am making, using the discord.py API in which basically everything is done in these async functions. Lets say I have an async method thats look like this: async def ...
3 votes
1 answer
5k views
How to make Python async functions callable in Jupyter without await
I've written a Python library that currently makes several independent HTTP requests in serial. I'd like to parallelize these requests without altering how the library is called by users, or requiring ...
5 votes
1 answer
6k views
How to run asyncio.run() within a FastAPI application?
I'm building an API with FastAPI and Playwright and I'm wondering how I should I write my code. This is Playwright Asyncio: import asyncio from playwright.async_api import async_playwright async def ...
0 votes
1 answer
4k views
Can not import async function from module in python
I am currently trying to import an (selfwritten) async function in python, but the compiler gives me an error message. See the minimalistic example below (yes I know that in this example async does ...
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
1 answer
2k views
How to override a sync function to run async code
I'm looking to define a new connection as shown here: https://udsoncan.readthedocs.io/en/latest/udsoncan/connection.html#defining-a-new-connection However, I want to call async code from there (i.e. ...
0 votes
1 answer
1k views
Running coroutines in different thread with same event loop
I want to run a coroutine in a different thread and get the result that the coroutine returns. class Main: def __init__(self, result_from_io_task=None): self._io_task_result = ...
0 votes
2 answers
201 views
Calling async code from syncronous function in Python
This problem is probably not complicated, but I'm new to async library and I just can't figure this out. Let's say I have a synchronous function from which I want to call an async function without ...
0 votes
1 answer
180 views
How to return (and print) multiple values in a function?
Here's my code: async def random(): return 1, 2 idk1, idk2 = random() print(idk1, idk2) After running, I received the error: cannot unpack non-iterable coroutine object. How can I fix this? Thank ...
0 votes
0 answers
85 views
How to use a async library in Django view?
I need to use a Python library that handles requests through the API of a web service. This library is an asyncio supported library. So I can't use it in a Django view by following the traditional and ...
0 votes
1 answer
74 views
Can I create a helper function for both async and sync environment?
I'm trying to create helper function for my projects, but some legacy projects are in sync environment. my helper function looks like: def func_for_async_and_sync(session, data): statement = ...