Skip to content

Instantly share code, notes, and snippets.

@tcitry
Created July 26, 2018 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcitry/48b5795a6b3f6d67199144116e016c09 to your computer and use it in GitHub Desktop.
Save tcitry/48b5795a6b3f6d67199144116e016c09 to your computer and use it in GitHub Desktop.
asyncio example
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