Last active
October 24, 2018 17:32
-
-
Save JialunC/0c473d99b32d05ef6e30d4f65336fe6f to your computer and use it in GitHub Desktop.
A simple async code
This file contains hidden or 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 | |
async def print_something_twice(): | |
print('Hello World') | |
await asyncio.sleep(1) | |
print('Hello to you three') | |
async def print_something(): | |
print('Hello to you two') | |
loop = asyncio.get_event_loop() | |
tasks = [loop.create_task(print_something_twice()), loop.create_task(print_something())] | |
loop.run_until_complete(asyncio.wait(tasks)) | |
loop.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment