I'm using tqdm for an async action in my Jupyter notebook -- should I use tqdm.notebook
(which I think gets me the right widget) or tqdm.asyncio
(which probably gets me the right behavior -- the items/sec calc seems off in my use).
Asked
Active
Viewed 495 times
6

retorquere
- 1,496
- 1
- 14
- 27
-
any advice on which of these you went with? i have a tqdm notebook but am considering trying to write my for loop with asyncio – steven hurwitt Apr 16 '21 at 22:21
-
I went with tqdm.notebook – retorquere Apr 17 '21 at 13:27
1 Answers
1
You can use an asyncio compatible version of tqdm in a jupyter notebook, by using the solution from this stackoverflow thread:
and replacing the tqdm you use, with the notebook version:
from tqdm.notebook import tqdm
async def factorial(name, number):
f = 1
for i in range(2, number + 1):
await asyncio.sleep(random.random())
f *= i
return f"Task {name}: factorial {number} = {f}"
requests = [factorial("A", 2), factorial("B", 3), factorial("C", 4)]
responses = [await f for f in tqdm(asyncio.as_completed(requests), total=len(requests))]

cokeman19
- 2,405
- 1
- 25
- 40

Collin Overbay
- 11
- 1