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

Breakpoint ignored when debugging a cell #8803

Closed
kimadeline opened this issue Jan 25, 2022 · 21 comments
Closed

Breakpoint ignored when debugging a cell #8803

kimadeline opened this issue Jan 25, 2022 · 21 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority notebook-debugging verified Verification succeeded
Milestone

Comments

@kimadeline
Copy link
Contributor

Testing #141223, followed the steps in microsoft/vscode#131469 to set up Jupyter debugging

Environment: macOS 11.6.2, Python 3.10.1, ipykernel==6.7.0
Jupyter extension version 2022.1.1001744497, VS Code 1.64.0-insider commit f93c696

Tried setting a breakpoint in a cell, and the cell would just get executed normally, the breakpoint was ignored.

The cell:

d = "no"
print(f"What is the value of d? {d}")
d = "yes"
print(f"What is the value of d now? {d}")

Content of the Jupyter output channel after I click on the Debug Cell button:

Info 11:52:11: Executing (status idle) silently Code = import ipykernel\nprint(ipykernel.__version__)
Info 11:52:11: Executing silently Code (completed) = import ipykernel\nprint(ipykernel.__version__)
Info 11:52:12: Executing (status idle) silently Code = import debugpy\ndebugpy.debug_this_thread()
Info 11:52:12: Executing silently Code (completed) = import debugpy\ndebugpy.debug_this_thread()
Info 11:52:12: Execute Cells request 3
Info 11:52:12: Execute Cell 3 ~/Documents/Sandbox/notebooks/notebook.ipynb
Info 11:52:12: Cell 3 executed with state Success
Warn 11:52:12: StdErr from Kernel Process [IPKernelApp] ERROR | Exception in control handler:

Warn 11:52:12: StdErr from Kernel Process Traceback (most recent call last):

Warn 11:52:12: StdErr from Kernel Process   File "/Users/kimiguel/Documents/Sandbox/notebooks/.othervenv/lib/python3.10/site-packages/ipykernel/kernelbase.py", line 281, in process_control

Warn 11:52:12: StdErr from Kernel Process     else:

Warn 11:52:12: StdErr from Kernel Process   File "/Users/kimiguel/Documents/Sandbox/notebooks/.othervenv/lib/python3.10/site-packages/ipykernel/kernelbase.py", line 856, in debug_request

Warn 11:52:12: StdErr from Kernel Process     async def debug_request(self, stream, ident, parent):

Warn 11:52:12: StdErr from Kernel Process   File "/Users/kimiguel/Documents/Sandbox/notebooks/.othervenv/lib/python3.10/site-packages/ipykernel/ipkernel.py", line 426, in do_debug_request

Warn 11:52:12: StdErr from Kernel Process     return await self.debugger.process_request(msg)

Warn 11:52:12: StdErr from Kernel Process   File "/Users/kimiguel/Documents/Sandbox/notebooks/.othervenv/lib/python3.10/site-packages/ipykernel/debugger.py", line 606, in process_request

Warn 11:52:12: StdErr from Kernel Process     elif self.is_started:

Warn 11:52:12: StdErr from Kernel Process   File "/Users/kimiguel/Documents/Sandbox/notebooks/.othervenv/lib/python3.10/site-packages/ipykernel/debugger.py", line 348, in stop

Warn 11:52:12: StdErr from Kernel Process     cleanup_transforms = get_ipython().input_transformer_manager.cleanup_transforms

Warn 11:52:12: StdErr from Kernel Process   File "/Users/kimiguel/Documents/Sandbox/notebooks/.othervenv/lib/python3.10/site-packages/ipykernel/debugger.py", line 232, in disconnect_tcp_socket

Warn 11:52:12: StdErr from Kernel Process     def disconnect_tcp_socket(self):

Warn 11:52:12: StdErr from Kernel Process   File "zmq/backend/cython/socket.pyx", line 640, in zmq.backend.cython.socket.Socket.disconnect

Warn 11:52:12: StdErr from Kernel Process zmq.error.ZMQError: No such file or directory

image

@kimadeline kimadeline added the bug Issue identified by VS Code Team member as probable bug label Jan 25, 2022
@rchiodo
Copy link
Contributor

rchiodo commented Jan 25, 2022

Seems to be caused by Python 3.10 changes. Works with latest IPython/IPykernel if using Python 3.9.

@rchiodo rchiodo removed their assignment Jan 25, 2022
@roblourens roblourens self-assigned this Jan 26, 2022
@greazer greazer added the important Issue identified as high-priority label Jan 27, 2022
@rchiodo
Copy link
Contributor

rchiodo commented Jan 27, 2022

Note run by line seems to work fine. It's only Debug Cell that fails (with IPython 8)

@greazer
Copy link
Member

greazer commented Jan 31, 2022

I have an environment with IPython 8 and debugging (hitting bps) is working just fine. Turns out that if I set a bp on the first line, then subsequent breakpoints seem to be hit. For example if I have this:

image

Breakpoints post the first one will be hit:
image

This would explain why run-by-line continues to work.

@rchiodo
Copy link
Contributor

rchiodo commented Feb 1, 2022

For me, I had to start debugging twice. Second run and the breakpoints fail to work (ZMQ throws error)

@r3m0t
Copy link
Contributor

r3m0t commented Feb 4, 2022

I just tried ipykernel's main branch and it works fine.
Looks to be this- ipython/ipykernel#855 as that's the only change since 6.8.0

@danieltomasz
Copy link

danieltomasz commented Feb 4, 2022

when switching to Python 3.9.10 breakpoints work ( the rest of env is the same)
Breakpoints also don't work in Jupyter lab when 3.10.2 is in use

@danieltomasz
Copy link

this might be related https://youtrack.jetbrains.com/issue/PY-47999
After manual Cython speedups compilation on macOS for Python 3.10 breakpoint are ignored

@danieltomasz
Copy link

danieltomasz commented Feb 7, 2022

With the new ipykernel 6.9.0 release, everything seems to work, for 3.10.2 and 3.9.10

@anmolsjoshi
Copy link

Experiencing this as well

python 3.9.5
ipykernel == 6.4.1
ipython == 7.29.0
VScode Version: 1.64.1 Commit: d6ee99e4c
Jupyter Extension: v2022.1.1001821375

@Zoxjib
Copy link

Zoxjib commented Feb 10, 2022

Experiencing this as well, both in VSCode and also in Jupyter's web UI when attempting to debug .ipynb files.
No issues when debugging .py files.

python 3.10.2
ipykernel == tested on 6.8.0 and 6.9.0
ipython == 8.0.1
VSCode version 1.64.1 Commit: d6ee99e4c
Jupyter Extension: v2022.1.1001821375

I've seen the exact error as reported by the OP, but I've also encountered the following error:

Traceback (most recent call last):
  File "C:\Users\username\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\username\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "c:\Users\username\.vscode\extensions\ms-python.python-2022.0.1814523869\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
    cli.main()
  File "c:\Users\username\.vscode\extensions\ms-python.python-2022.0.1814523869\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 444, in main
    run()
  File "c:\Users\username\.vscode\extensions\ms-python.python-2022.0.1814523869\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 285, in run_file
    runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
  File "C:\Users\username\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 269, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "C:\Users\username\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "C:\Users\username\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "e:\Programming\Github\python\MIT 6.0001\Ses3.ipynb", line 16, in <module>
    "execution_count": null,
NameError: name 'null' is not defined

@danieltomasz
Copy link

danieltomasz commented Feb 10, 2022

When creating new environment using code below, debugging works with VERSION=3.9.10 but not with VERSION=3.10.2 (With 3.10.2 will work only when the first line in the cell is debugged as in this issue ipython/ipykernel#841)
I am on macOS 12.3,
Visual Studio 1.64.2,
Jupyter Extension v2022.2.100182281
pyenv 2.2.4

pyenv install 3.10.2
pyenv install 3.9.10
make install VERSION=3.9.10
make install VERSION=3.10.2

Content of the makefile:

.ONESHELL:

.PHONY: install

PROJECT=debug
VERSION?=3.10.2
VENV=${PROJECT}-${VERSION}
VENV_DIR=$(shell pyenv root)/versions/${VENV}
PYTHON=${VENV_DIR}/bin/python

install:
	@echo "Installing $(VENV)"
	pyenv virtualenv ${VERSION} ${VENV}
	pyenv local ${VENV}
	$(PYTHON) -m pip cache purge 
	$(PYTHON) -m pip  install -U pip
	$(PYTHON) -m pip install wheel
	$(PYTHON) -m pip install ipykernel
	$(PYTHON) -m ipykernel install --user --name ${VENV}

@rchiodo
Copy link
Contributor

rchiodo commented Feb 10, 2022

I think this is debugpy/pydevd's fault. At least it is sent the breakpoints but it doesn't fire them.

@rchiodo
Copy link
Contributor

rchiodo commented Feb 10, 2022

Logging an issue on debugpy:
microsoft/debugpy#844

@rchiodo rchiodo removed their assignment Feb 10, 2022
@rchiodo rchiodo modified the milestones: January 2022 Recovery, February 2022 Feb 10, 2022
@fabioz
Copy link

fabioz commented Feb 18, 2022

Hi all, this was a change of behavior in Python 3.10 itself (see: https://mail.python.org/archives/list/python-dev@python.org/thread/VXW3TVHVYOMXDQIQBJNZ4BTLXFT4EPQZ/).

I provided a pull request to IPython: ipython/ipython#13535 (still pending).

If anyone wants to try it and is comfortable patching the installed version, you can run in the notebook:

from IPython.core import interactiveshell
print(interactiveshell.__file__)

And then open the file printed and apply the patch from ipython/ipython#13535 (don't forget to restart the notebook afterwards).

p.s.: Given that this issue is an interaction between Python 3.10/ipython/debugpy, I think we can close the issue on vscode-jupyter...

@rchiodo
Copy link
Contributor

rchiodo commented Feb 18, 2022

Thanks @fabioz

@greazer
Copy link
Member

greazer commented Feb 24, 2022

Closing per @fabioz's suggestion.

@greazer greazer closed this as completed Feb 24, 2022
@fabioz
Copy link

fabioz commented Feb 24, 2022

As a note, it seems there's another use-case where this happens (with hypothesis: microsoft/debugpy#837), so, I'll provide a bugfix in debugpy itself which will fix both.

@roblourens
Copy link
Member

Anything to verify here?

@roblourens roblourens added the verification-steps-needed Steps to verify are needed for verification label Feb 25, 2022
@rchiodo
Copy link
Contributor

rchiodo commented Feb 25, 2022

I think we have to wait for the fix in ipykernel, so probably no?

@rchiodo rchiodo added verified Verification succeeded and removed verification-steps-needed Steps to verify are needed for verification labels Feb 25, 2022
@fabioz
Copy link

fabioz commented Feb 25, 2022

I ended up doing a fix in the debugger itself too (see comments in the PR: microsoft/debugpy#851).

So, this does need a new debugger release...

@johnfkraus
Copy link

Can't help but observe a seeming hair trigger for closing issues.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 27, 2023
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 important Issue identified as high-priority notebook-debugging verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

10 participants