Created
July 26, 2018 09:35
-
-
Save tcitry/48b5795a6b3f6d67199144116e016c09 to your computer and use it in GitHub Desktop.
asyncio example
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 | |
@asyncio.coroutine | |
def hello(): | |
print("hello start") | |
ret = yield from asyncio.sleep(2) | |
print('hello end') | |
@asyncio.coroutine | |
def world(): | |
print('world start') | |
ret = yield from asyncio.sleep(2) | |
print('world end') | |
if __name__ == '__main__': | |
loop = asyncio.get_event_loop() | |
tasks = [hello(), world()] | |
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