-
-
Save davidfarrugia/f43c5978bd14bba4aa429547243afa54 to your computer and use it in GitHub Desktop.
A simple introduction to asyncio in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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