Skip to content

Instantly share code, notes, and snippets.

@davidfarrugia
Created Oct 31, 2021
Embed
What would you like to do?
A simple introduction to asyncio in Python
import asyncio
# define our coroutine
async def say_hello():
print('Hello')
# asynchronous sleep of 1 second
await asyncio.sleep(1)
print('World')
# we initialise our event loop
loop = asyncio.get_event_loop()
# we run our coroutine in the event loop until it is completed
loop.run_until_complete(say_hello())
# close the event loop
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment