All Questions
65 questions
154
votes
3
answers
205k
views
asyncio.sleep() vs time.sleep()
When I go to the asyncio page, the first example is a hello world program. When I run it on python 3.73, I can't see any different from the normal one. can anyone tell me the difference and give a non-...
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 ...
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 ...
80
votes
13
answers
94k
views
How to combine Celery with asyncio?
How can I create a wrapper that makes celery tasks look like asyncio.Task? Or is there a better way to integrate Celery with asyncio?
@asksol, the creator of Celery, said this::
It's quite common ...
107
votes
7
answers
106k
views
How can I wrap a synchronous function in an async coroutine?
I'm using aiohttp to build an API server that sends TCP requests off to a seperate server. The module that sends the TCP requests is synchronous and a black box for my purposes. So my problem is that ...
33
votes
3
answers
164k
views
sys:1: RuntimeWarning: coroutine was never awaited
I'm trying to write a request handler to help me send request in async mode. It prompt when I close the python terminal with Ctrl+D or exit()
It shows sys:1: RuntimeWarning: coroutine was never ...
11
votes
2
answers
2k
views
Tulip/asyncIO: why not all calls be async and specify when things should be synchronous?
I went to the SF Python meetup when Guido talked about Tulip, the future asyncIO library for asynchronous operations in Python.
The take away is that if you want something to be run asynchronously ...
85
votes
5
answers
105k
views
how to add a coroutine to a running asyncio loop?
How can one add a new coroutine to a running asyncio loop? Ie. one that is already executing a set of coroutines.
I guess as a workaround one could wait for existing coroutines to complete and then ...
9
votes
2
answers
11k
views
C-Python asyncio: running discord.py in a thread
I have to launch discord.py in a separate thread since I can't block my main thread.
It is a game server C/Python 3.7 (ubuntu 18)
C code:
int pysDiscord_Init;
...
PyObject *psv_discord;
...
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 ...
30
votes
2
answers
12k
views
Does `await` in Python yield to the event loop?
I was wondering what exactly happens when we await a coroutine in async Python code, for example:
await send_message(string)
(1) send_message is added to the event loop, and the calling coroutine ...
14
votes
4
answers
19k
views
asynchronous aiohttp requests fails, but synchronous requests succeed
With the following code I get Cannot connect to host ...:443 ssl:True when I use the asynchronous aiohttp. When I use synchronous requests, it succeeds.
The whitehouse.gov links fail, but the google....
30
votes
3
answers
45k
views
How to use an async for loop to iterate over a list?
So I need to call an async function for all items in a list. This could be a list of URLs and an async function using aiohttp that gets a response back from every URL. Now obviously I cannot do the ...
29
votes
3
answers
9k
views
Yield from coroutine vs yield from task
Guido van Rossum, in his speech in 2014 on Tulip/Asyncio shows the slide:
Tasks vs coroutines
Compare:
res = yield from some_coroutine(...)
res = yield from Task(some_coroutine(......
24
votes
1
answer
35k
views
How to properly use asyncio run_coroutine_threadsafe function?
I am trying to understand asyncio module and spend about one hour with run_coroutine_threadsafe function, I even came to the working example, it works as expected, but works with several limitations.
...