Skip to content

Instantly share code, notes, and snippets.

@koladev32
Created September 3, 2019 21:52
Show Gist options
  • Save koladev32/5dce6ef78b763339af73785224c57506 to your computer and use it in GitHub Desktop.
Save koladev32/5dce6ef78b763339af73785224c57506 to your computer and use it in GitHub Desktop.
Introduction to asynchronous programming with python Part 1 : asyncio your code
import asyncio
async def hello():
print("Hello")
await asyncio.sleep(2)
print("World")
async def main():
await asyncio.gather(hello(),hello(),hello())
if __name__=='__main__':
import time
s = time.perf_counter()
asyncio.run(main())
exec_time = time.perf_counter() - s
print(f"Program executed in {exec_time:0.2f} seconds.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment