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

Output from functions running out of the standard execution path are captured and displayed in VS Code but not in Jupyter Notebook #15996

Open
rsnell-usgs opened this issue Sep 5, 2024 · 4 comments · May be fixed by #16169
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug ipywidgets Rendering, loading, saving, anything to do with IPyWidgets

Comments

@rsnell-usgs
Copy link

  • VS Code version: 1.92.2
  • Jupyter Extension version (available under the Extensions sidebar): 2024.7.0
  • Python Extension version (available under the Extensions sidebar): 2024.12.3
  • OS (Windows | Mac | Linux distro) and version: Windows 10
  • Python and/or Anaconda version: 3.12.4
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
  • Jupyter server running: Local | Remote | NA: Local

Expected behaviour

I'm not sure what is the correct behavior, but I would expect VS Code and Jupyter Notebook to display output from background processes and functions called outside of the standard execution flow in a similar manner.

Actual behaviour

VS Code displays any kind of output (stdout, stderr, rich content/HTML) from background processes or functions running out of the standard execution path whereas Jupyter Notebook v7 does not. Version 6 of Jupyter Notebook does appear capture, and display output the same as VS Code.

Steps to reproduce:

  • Execute the following code:
from ipywidgets import Button
from IPython.display import display


button = Button(description="Click Me!")

display(button)

def on_button_clicked(b):
        print("Button clicked.")

button.on_click(on_button_clicked)
  • Click the displayed button.
    • VS Code will display the stdout message
    • Jupyter Notebook will not display anything.

I developed an entire notebook in VS Code that worked perfectly only to fund that as I tested it in Jupyter Notebook little of my output was displayed for users running Jupyter Notebook v7 (v6 appears to behave as VS Code does). I don't know which behavior of the two is correct but whatever it is they should work similarly.

@rsnell-usgs rsnell-usgs added the bug Issue identified by VS Code Team member as probable bug label Sep 5, 2024
@DonJayamanne
Copy link
Contributor

Thank you for filing this issue and sorry you are running into this.
& thanks for digging into this and sharing the information about the differences in different versions.

Version 6 of Jupyter Notebook does appear capture, and display output the same as VS Code.

This would seem to be a regression in Jupyter Notebook 7, I know plenty of users have relied on this working in the past.
In fact we have tests to ensure this works as expected. See here
https://github.com/microsoft/vscode-jupyter/blob/f44cd0f735239e12cd0c46a390e53802dd9471a5/src/test/datascience/widgets/notebooks/button_widgets.ipynb & https://github.com/microsoft/vscode-jupyter/blob/b80fb940fd8875ba976e049ce4670c8f34099f7b/src/test/datascience/widgets/notebooks/button_widget_comm_msg.ipynb

Closing as this is by design.
I do not expect Jupyter 7 to change this behaviour, I'd suggest filing an issue on their repo
Basically I want to avoid issues where Jupyter Notebook 7 has a bug and then we just replicate the same bug deliberately. Without first confirming the fact that its not a bug.

@DonJayamanne DonJayamanne added notebook-execution Kernels issues (start/restart/switch/execution, install ipykernel) ipywidgets Rendering, loading, saving, anything to do with IPyWidgets *question Issue represents a question, should be posted to StackOverflow (VS Code) and removed bug Issue identified by VS Code Team member as probable bug labels Sep 5, 2024
@rsnell-usgs
Copy link
Author

Hi. Thanks for the response and sorry to bring it up again but I have dug further into this issue by creating many different environments in Anaconda to test versions and made some discoveries.

I noticed as I was testing this in JupyterLab (4.2.5) that it looks like the output from a source such as a widget button click is directed to the Log rather than to the cell output. Apparently, it has been working this way in JupyterLab for several years and with Jupyter Notebook v7 seemingly now being based on a JupyterLab code foundation rather than a continuation of the legacy v6 and older Notebook code v7 has now too taken on this behavior. I do not believe it is a bug in v7. From all I am reading this is intended behavior and the VS Code extension is not reflecting the change.

See this comment:
Presently, the Jupyter notebook classic interface is a little more forgiving when not properly handling widget output. Importantly, you’ll have more resilent code if you update to the more modern way widgets output is handled; I suspect the notebook classic interface won’t be as forgiving when the newer version of what is presently the classic interface has the similar underlying machinery as JupyterLab, which is the plan going forward.
in this post on the Jupyter Discourse:
https://discourse.jupyter.org/t/jupyterlab-output-in-log-rather-than-cell/13419/2?u=fomightez

Other posts with similar issues:
https://stackoverflow.com/questions/66286352/print-output-going-to-log-window-instead-of-cell-in-jupyter-lab
https://stackoverflow.com/questions/78003361/display-output-going-to-log-window-instead-of-cell-in-jupyter-lab

Obviously I need to adjust my code to use the output widget for my original output to be replicated in modern Notebook and JupyterLab but VS Code should mirror this behavior to prevent people like me developing exclusively in VS Code and then finding key output is not displayed in Jupyter Notebook/JupyterLab

@DonJayamanne DonJayamanne reopened this Sep 6, 2024
@DonJayamanne DonJayamanne added bug Issue identified by VS Code Team member as probable bug and removed *question Issue represents a question, should be posted to StackOverflow (VS Code) labels Oct 2, 2024
@DonJayamanne
Copy link
Contributor

History: This was deliberately added here #9503
Though the changes were good, we just need to filter out outputs from comm_msg.

@DonJayamanne DonJayamanne linked a pull request Oct 29, 2024 that will close this issue
1 task
@DonJayamanne
Copy link
Contributor

See also jupyter-widgets/ipywidgets#3949

@DonJayamanne DonJayamanne removed the notebook-execution Kernels issues (start/restart/switch/execution, install ipykernel) label Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug ipywidgets Rendering, loading, saving, anything to do with IPyWidgets
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants