Created
April 17, 2025 17:07
-
-
Save vanviethieuanh/0b07fa1c8f6a34abed9531439d737e50 to your computer and use it in GitHub Desktop.
Example progress bar with asyncio gather in Python.
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
| #!/usr/bin/env python3 | |
| import asyncio | |
| from tqdm.asyncio import tqdm | |
| async def task(i): | |
| await asyncio.sleep(i) | |
| print(i) | |
| async def main(): | |
| arr = [2, 1, 2, 1, 5, 1, 2] | |
| await tqdm.gather(*[asyncio.create_task(task(i)) for i in arr]) | |
| if __name__ == "__main__": | |
| asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment