In Python, what is the actual difference between await
ing a coroutine and using asyncio.run()
? They both seem to run a coroutine, the only difference that I can see being that await
can only be used in a coroutine.
That is the exact difference. There should be exactly one call to asyncio.run()
in your code, which will block until all coroutines have finished.
Inside any coroutine, you can use await
to suspend the current function, and asyncio
will resume the function at some future time. All of this happens inside the asyncio.run()
function, which schedules what functions can run when.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With