Am attempting a tqdm progress bar with asyncio tasks gathered.
Want the progress bar to be progressively updated upon completion of a task. Tried the code:
import asyncio
import tqdm
import random
async def factorial(name, number):
f = 1
for i in range(2, number+1):
await asyncio.sleep(random.random())
f *= i
print(f"Task {name}: factorial {number} = {f}")
async def tq(flen):
for _ in tqdm.tqdm(range(flen)):
await asyncio.sleep(0.1)
async def main():
# Schedule the three concurrently
flist = [factorial("A", 2),
factorial("B", 3),
factorial("C", 4)]
await asyncio.gather(*flist, tq(len(flist)))
asyncio.run(main())
...but this simply completes the tqdm bar and then processes factorials.
Is there a way to make the progress bar move upon completion of each asyncio task?