microsoft / vscode-jupyter

VS Code Jupyter extension
https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter
MIT License
1.28k stars 290 forks source link

textbase tqdm bar does not display correctly #15701

Open ydmykr opened 4 months ago

ydmykr commented 4 months ago

Here's the codes:

from time import sleep
from tqdm import tqdm

for i in tqdm(range(100)):
    for j in tqdm(range(10), leave=False):
        sleep(0.1)

When running in the terminal, it shows correctly. It returns two progress bars, one for theiand one for thej in the loop.

However, when running in the jupyter notebook or Interactive Window, only the outermost i loop is displayed, and the progress bar of thej loop contained therein is not displayed.

ydmykr commented 4 months ago

Related on StackOverflow: https://stackoverflow.com/questions/78507717/nested-tqdm-loading-bars-not-working-in-vscode-interactive-window

DonJayamanne commented 2 months ago

Looks like something broke in tqdm, as this doesn't work properly in Jupyter lab either (though different issues).

Image

DonJayamanne commented 2 months ago

@ydmykr As a work around, try using from tqdm.notebook import tqdm instead of from tqdm import tqdm

Personal Notes Python code used ```python from time import sleep from tqdm import tqdm # from tqdm.notebook import tqdm for i in tqdm(range(2)): for j in tqdm(range(5), leave=False): sleep(1.1) ``` This produced the following outputs, and then when used in VSCode Tested the following code in vscode to compress the outputs using `compressOutputItemStreams` The outputs are as expected. I.e. compression works correctly. Also found that while debugging Jupyter extension, when the output is sent out slowly to VS Code, then we can see the right outputs, i.e. we can see two lines (as expected) Looks like some race condition in displaying the outputs or the like. ```typescript const lines = [ "\r 0%| | 0/2 [00:00 { result = compressOutputItemStreams([result.buffer, valueBytesFromString(line).buffer]).data; value = result.buffer.toString(); console.log(value); }); value = result.buffer.toString().toString(); ```
DonJayamanne commented 2 months ago

WORK AROUND

import tqdm.notebook instead of tqdm I.e.

from time import sleep
from tqdm.notebook import tqdm

for i in tqdm(range(100)):
    for j in tqdm(range(10), leave=False):
        sleep(0.1)
Jorritboer commented 2 months ago

Thank you for looking into this (minor) issue. The workaround doesn't seem to work for me either however.

https://github.com/user-attachments/assets/e2a8d49b-924d-4fc6-91ee-2748683e4b9c

b-a0 commented 1 month ago

The workaround works for me in VS Code on Windows:

tqdm

Version info:

vs code:

Version: 1.92.0 (system setup)
Commit: b1c0a14de1414fcdaa400695b4db1c0799bc3124
Date: 2024-07-31T23:26:45.634Z
Electron: 30.1.2
ElectronBuildId: 9870757
Chromium: 124.0.6367.243
Node.js: 20.14.0
V8: 12.4.254.20-electron.0
OS: Windows_NT x64 10.0.20348

conda environment:

- python=3.9.19
- ipython=7.33.0
- tqdm=4.66.5
cceyda commented 1 month ago

tqdm has been really unreliable on vscode notebooks lately, it stops working suddenly, like it will render on previous cell and will stop working at next cell 🤷 not sure if issue with ipywidgets,tqdm or vscode. For today the issue seems happen while using remote kernels only and I can't get rich progress bar to render either, so not a tqdm issue this time

DonJayamanne commented 1 month ago

For today the issue seems happen while using remote kernels only and I can't get rich progress bar to render either, so not a tqdm issue this time

Sorry you are running into this and thank you for sharing this information. If you are using the widgets, then please can you file a new issue, as this issue focuses on non-widgtets (text based) Please do share the information required to repro this.