microsoft / vscode-jupyter

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

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 2 months ago

rsnell-usgs commented 2 months ago

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:

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.

DonJayamanne commented 2 months ago

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.

rsnell-usgs commented 2 months ago

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 commented 3 weeks ago

History: This was deliberately added here https://github.com/microsoft/vscode-jupyter/issues/9503 Though the changes were good, we just need to filter out outputs from comm_msg.

DonJayamanne commented 3 weeks ago

See also https://github.com/jupyter-widgets/ipywidgets/issues/3949