Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS Code Buffering Issue when Printing Outputs in Jupyter Notebooks #13565

Closed
diftimieMSFT opened this issue May 22, 2023 · 5 comments
Closed
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug notebook-output
Milestone

Comments

@diftimieMSFT
Copy link

diftimieMSFT commented May 22, 2023

Does this issue occur when all extensions are disabled?: Not sure (need extensions to use Jupyter)

  • VS Code Version: 1.78.2
  • OS Version: Windows 11 Enterprise 22H2
  • Using Jupyter Notebooks in VS Code
  • Launching VS Code from WSL2 Ubuntu 18.04 terminal
  • Connecting Jupyter Notebook with conda environment (although issue seems to repro without conda)
  • Jupyter extension v2023.4.10112418018

Steps to Reproduce:

  1. Open VS code from WSL2 with code . (where conda environments are already initialized)
  2. Create a new Jupyter Notebook in VS Code
  3. Connect the Jupyter Notebook to a conda environment as the python kernel (select Kernel >> Python Environments >> conda environment)
  4. Populate the first python cell of the jupyter notebook with the following code:
    # Prompt the user 10 times (0-9 times) and ask them to enter the answer number
    # this will then print the question number and answer number together
    for question_num in range(0, 10):
        answer_num = input("Enter the Answer Number:")
        print(f"Question Num = #{question_num}; Answer Num = #{answer_num}")
  5. Execute the cell and enter your answers as 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 (one at a time). Note that the answer numbers always remain in sync with the question numbers, but the bug shows up when the question-answer pairs aren't always being displayed to the console after providing the answer number. For example:

Here I'm about to enter 3 as an answer after having entered "0", "1", and "2"; Only "0" and "1" have flushed:
image

Here I just entered 3 and am about to enter 4 and all 4 previous response ("0", "1", "2", "3") have flushed:
image

Note that this issue doesn't occur on IDEs such as JupyterLab and Jupyter Notebooks, only on VS Code Jupyter Notebooks.

Solution/Workaround:
The solution/workaround was to add a sys.stdout.flush() before prompting the next time around, as shown below:
image

It would be good however for VS Code to not do this buffering, especially since JupyterLab and Jupyter Notebook don't run into this issue.

@rebornix
Copy link
Member

I can actually reproduce. I can't recall if we have any buffering in Jupyter or core.

@rebornix rebornix added the bug Issue identified by VS Code Team member as probable bug label May 25, 2023
@DonJayamanne DonJayamanne transferred this issue from microsoft/vscode May 25, 2023
@loganpowell
Copy link

Had no issues up until today with printing... was this a recently introduced change?

@jonaspleyer
Copy link

Having the same issue here. I am using rusts pyo3 crate to generate python bindings. Works flawless in the command line without any notebook.

@DonJayamanne
Copy link
Contributor

DonJayamanne commented Dec 4, 2023

Blocked on #11295, #14422

@DonJayamanne
Copy link
Contributor

Duplicate of #13039

@DonJayamanne DonJayamanne marked this as a duplicate of #13039 Dec 12, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug notebook-output
Projects
None yet
Development

No branches or pull requests

6 participants