vscode-jupyter icon indicating copy to clipboard operation
vscode-jupyter copied to clipboard

"Run All" button executes cells in random order

Open y1zhou opened this issue 1 year ago • 4 comments

Applies To

  • [X] Notebooks (.ipynb files)
  • [ ] Interactive Window and/or Cell Scripts (.py files with #%% markers)

What happened?

Steps taken

  1. Create new notebook
  2. Write x = 1 in cell 1, x in cell 2, y=2 in cell 3, y in cell 4, etc.
  3. Click the "Run All" button, or hover on cell 1 and click "Execute Cell and Below"

Expected outcome

Cells get executed in order.

Observed outcome

Cell 2n raises a NameError of undefined variable because cell 2n-1 was not executed.

VS Code Version

Version: 1.92.1 Commit: eaa41d57266683296de7d118f574d0c2652e1fc4 Date: 2024-08-07T20:16:39.455Z Electron: 30.1.2 ElectronBuildId: 9870757 Chromium: 124.0.6367.243 Node.js: 20.14.0 V8: 12.4.254.20-electron.0 OS: Darwin arm64 23.5.0

Jupyter Extension Version

v2024.7.0

Jupyter logs

14:36:21.029 [warn] Cell completed with errors Qd [Error]: name 'x' is not defined
    at n.execute (/home/~/.vscode-server/extensions/ms-toolsai.jupyter-2024.7.0-linux-x64/dist/extension.node.js:297:4958) {
  ename: 'NameError',
  evalue: "name 'x' is not defined",
  traceback: [
    '\x1B[0;31m---------------------------------------------------------------------------\x1B[0m',
    '\x1B[0;31mNameError\x1B[0m                                 Traceback (most recent call last)',
    'Cell \x1B[0;32mIn[1], line 1\x1B[0m\n\x1B[0;32m----> 1\x1B[0m \x1B[43mx\x1B[49m\n',
    "\x1B[0;31mNameError\x1B[0m: name 'x' is not defined"
  ]
}
14:36:21.029 [warn] Cancel all remaining cells due to cancellation or failure in execution

Coding Language and Runtime Version

Python v3.12.3

Language Extension Version (if applicable)

v2024.12.3

Anaconda Version (if applicable)

conda 23.11.0, micromamba 1.5.8

Running Jupyter locally or remotely?

Remote

y1zhou avatar Aug 14 '24 06:08 y1zhou

that's strange - I can't think of why that would happen. Just to confirm, if you execute the cells one by one, do they run successfully?

Can you try creating a new profile and just installing the python and jupyter extensions and see if it still repro's.

if so, can you set "jupyter.logging.level": "trace", go through the steps again, and post the logs from that run.

amunger avatar Aug 14 '24 16:08 amunger

that's strange - I can't think of why that would happen. Just to confirm, if you execute the cells one by one, do they run successfully?

Correct I can still shift+enter all the way down to the end without problems.

Can you try creating a new profile and just installing the python and jupyter extensions and see if it still repro's.

This was a good call! The issue did not reproduce in the new profile. When I switched back to the default profile it also seems to run all cells sequentially without problems, although I had to re-install the Python and Jupyter extensions for some reason.

I'm going to close the issue for now and add comments if the problem comes back. Thanks for the help!

y1zhou avatar Aug 15 '24 03:08 y1zhou

I think what I am experiencing might be related to this, though to me it looks more like cells are executed in a random order, causing it to seem like some are skipped.

https://github.com/user-attachments/assets/9aaeb26d-2725-4ca9-b379-aeb6d0bb200a

With a log (though from a different execution) that confirms the strange order:

18:06:22.022 [debug] Handle Execution of Cells 0,1,2,3,4,5 for ~/Dropbox/University/ES9/jupyterbug.ipynb
18:06:22.120 [trace] Cell Index:2 sent to kernel
18:06:22.141 [trace] Start cell 2 execution @ 1724342782140 (clear output)
18:06:22.145 [debug] Kernel acknowledged execution of cell 2 @ 1724342782140
18:06:22.150 [trace] Cell 2 completed in 0.009s (start: 1724342782140, end: 1724342782149)
18:06:22.151 [trace] Cell 2 executed successfully
18:06:22.154 [trace] Cell Index:4 sent to kernel
18:06:22.163 [trace] Start cell 4 execution @ 1724342782163 (clear output)
18:06:22.165 [debug] Kernel acknowledged execution of cell 4 @ 1724342782163
18:06:22.168 [trace] Cell 4 completed in 0.005s (start: 1724342782163, end: 1724342782168)
18:06:22.170 [trace] Cell 4 executed successfully
18:06:22.173 [trace] Cell Index:3 sent to kernel
18:06:22.185 [trace] Start cell 3 execution @ 1724342782185 (clear output)
18:06:22.188 [debug] Kernel acknowledged execution of cell 3 @ 1724342782185
18:06:22.191 [trace] Cell 3 completed in 0.006s (start: 1724342782185, end: 1724342782191)
18:06:22.192 [trace] Cell 3 executed successfully
18:06:22.195 [trace] Cell Index:0 sent to kernel
18:06:22.206 [trace] Start cell 0 execution @ 1724342782205 (clear output)
18:06:22.208 [debug] Kernel acknowledged execution of cell 0 @ 1724342782205
18:06:22.216 [trace] Cell 0 completed in 0.011s (start: 1724342782205, end: 1724342782216)
18:06:22.218 [trace] Cell 0 executed successfully
18:06:22.222 [trace] Cell Index:5 sent to kernel
18:06:22.231 [trace] Start cell 5 execution @ 1724342782231 (clear output)
18:06:22.233 [debug] Kernel acknowledged execution of cell 5 @ 1724342782231
18:06:22.240 [trace] Cell 5 completed in 0.009s (start: 1724342782231, end: 1724342782240)
18:06:22.245 [trace] Cell 5 executed successfully
18:06:22.247 [trace] Cell Index:1 sent to kernel
18:06:22.260 [trace] Start cell 1 execution @ 1724342782260 (clear output)
18:06:22.261 [debug] Kernel acknowledged execution of cell 1 @ 1724342782260
18:06:22.268 [trace] Cell 1 completed in 0.007s (start: 1724342782260, end: 1724342782267)
18:06:22.270 [trace] Cell 1 executed successfully

peterkrull avatar Aug 22 '24 16:08 peterkrull

I also ran into the issue a few times and it does seem to happen randomly. Sometimes it works fine after restarting the kernel.

y1zhou avatar Aug 23 '24 00:08 y1zhou

@amunger Following up to see if additional information is needed. Thanks!

y1zhou avatar Aug 30 '24 07:08 y1zhou

+1

I have the same issue for a few weeks. Happens only sometimes and usually causes NameError: name 'X' is not defined as the cell that should define it runs before, so cells look as though they are skipped, but might be just random order of execution. Also Shift+Enter works good for me.

SmallhillCZ avatar Sep 04 '24 12:09 SmallhillCZ

Yeah this is pretty much breaking issue for those of us that experience it. I would be happy to provide system/configuration information if needed.

peterkrull avatar Sep 04 '24 12:09 peterkrull

This is a duplicate of https://github.com/microsoft/vscode-jupyter/issues/15746 Please install the latest pre-release version of the Jupyter extension (2024.8.***) or the latest release (should get released some time today/tomorrow).

@peterkrull @SmallhillCZ @y1zhou If the problem still persists, please do ping here or feel free to create a new issue.

  • Open the extensions page, search for Jupyter and click the button Switch to Pre-Release Version (image for reference only, on how to locate and install the pre-release version) Screenshot 2023-02-04 at 09 24 37

DonJayamanne avatar Sep 04 '24 23:09 DonJayamanne