Created
September 5, 2023 16:14
-
-
Save nhalstead/fb1be4fb0ca3a42decb008964c21707b to your computer and use it in GitHub Desktop.
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 | |
from asyncio import gather | |
async def long_process(ith: int): | |
print(f"foo {ith}") | |
await asyncio.sleep(2) | |
print(f"bar {ith}") | |
return f"result {ith}" | |
async def main(): | |
(first, second) = await gather(long_process(1), long_process(2)) | |
print(first) | |
print(second) | |
if __name__ == '__main__': | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.pythontutorial.net/python-concurrency/python-asyncio-wait/