Created
September 3, 2019 21:52
-
-
Save koladev32/5dce6ef78b763339af73785224c57506 to your computer and use it in GitHub Desktop.
Introduction to asynchronous programming with python Part 1 : asyncio your 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 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