Skip to content

Instantly share code, notes, and snippets.

@vanviethieuanh
Created April 17, 2025 17:07
Show Gist options
  • Save vanviethieuanh/0b07fa1c8f6a34abed9531439d737e50 to your computer and use it in GitHub Desktop.
Save vanviethieuanh/0b07fa1c8f6a34abed9531439d737e50 to your computer and use it in GitHub Desktop.
Example progress bar with asyncio gather in Python.
#!/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