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

'debug adapter' error in jupyter notebook #1166

Closed
PeterM18 opened this issue Dec 26, 2022 · 17 comments
Closed

'debug adapter' error in jupyter notebook #1166

PeterM18 opened this issue Dec 26, 2022 · 17 comments

Comments

@PeterM18
Copy link

PeterM18 commented Dec 26, 2022

Type: Bug

ACTUAL BEHAVIOR
When running debug on a particular cell in the notebook below, the debugging halts and an error message appears.
https://github.com/phlippe/uvadlc_notebooks/blob/master/docs/tutorial_notebooks/tutorial5/Inception_ResNet_DenseNet.ipynb

The cell is the one with the first line: imgs, _ = next(iter(train_loader)).

With a breakpoint on that cell, the debugger stops normally. I then seek to step to the next line and then the debugger greys out VSCode and shows the following error message:

"Couldn't find a debug adapter descriptor for debug type 'Python Kernel Debug Adapter' (extension might have failed to activate)"

This occurs with multiple instances of the message: "I also get a "Failed to launch debugger for child process XXX"

I ran the debugger for multiple cells above this cell and had no problems. I've tried reinstalling and switching to the pre-release versions of both the Python and Jupyter extensions (both Microsoft) and restarting vscode each time. The error occurs in all cases. (BTW, I tried to submit this bug report by using 'Python: Report Issue', but I do not have that option.)

EXPECTED BEHAVIOR:
On debugging the cell, after stepping over the first line of code, the debugger should move to the 2nd line of code with no error message.

Extension version: 2022.20.1
VS Code version: Code 1.74.2 (e8a3071ea4344d9d48ef8a4df2c097372b0c5161, 2022-12-20T10:27:19.253Z)
OS version: Linux x64 5.10.0-20-amd64
Modes:
Sandboxed: No

System Info
Item Value
CPUs Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz (8 x 3247)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: disabled_software
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) 1, 1, 1
Memory (System) 23.44GB (4.06GB free)
Process Argv --unity-launch --crash-reporter-id d556c1c3-5a8d-4575-970a-2b1a16582954
Screen Reader no
VM 0%
DESKTOP_SESSION plasma
XDG_CURRENT_DESKTOP KDE
XDG_SESSION_DESKTOP KDE
XDG_SESSION_TYPE x11
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscoreces:30445986
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593:30376534
pythonvs932:30410667
cppdebug:30492333
vsclangdf:30486550
c4g48928:30535728
dsvsc012cf:30540253
azure-dev_surveyone:30548225
pyindex848cf:30577861
nodejswelcome1cf:30587006
3biah626:30602489
gswce1:30612156
iaj6b796:30613358
f6dab269:30613381
fim-prod:30623723
vscup:30628656

@PeterM18
Copy link
Author

Here's a copy of my log from VS CODE start to attempted execution of the problematic line of code. I can't tell what is triggering the problem.

vscode-app-1672085861288.log

@PeterM18
Copy link
Author

PeterM18 commented Dec 29, 2022

Evidently, the problem is due to the debugger having problems with multiprocessing.

I get the "Failed to launch debugger for child process XXX" error once per multiprocessing thread. And, I can make the error disappear by removing multiprocessing (where it is possible to do so).

I can debug the line imgs, _ = next(iter(train_loader)) without problems by altering train_loader to use no multiprocessing (that is, by removing 'num_workers=4').

However, most of the later code depends on Pytorch Lightning, specifically the pl.Trainer module, for which multiprocessing cannot be turned off--as far as I can tell. So, I can't run the debugger on this code to better understand it.

I did find a suggestion on the web to add "subProcess": true, to my launch.json file. This made no difference for me (I'm using the Community version of VSCode).

@PeterM18
Copy link
Author

Note that using just one thread does not prevent the problem, multiprocessing has to be turned off entirely. So, for example, if I set 'num_workers=1' in train_loader, the debugger problem occurs. It only disappears with num_workers removed entirely. As for pl.Trainer, even if I tell it to use one device (thread in case my case), I still get the debugger error. There seems to be no way to turn of multiprocessing for pl.Trainer. It would be tremendously helpful if the debugger would work if multiprocessing were set to just one thread.

@brettcannon brettcannon transferred this issue from microsoft/vscode-python Jan 3, 2023
@int19h
Copy link
Contributor

int19h commented Jan 5, 2023

Jupyter debugger doesn't support debugging subprocesses currently; this is tracked at microsoft/vscode-jupyter#9886

@int19h int19h closed this as completed Jan 5, 2023
@PeterM18
Copy link
Author

PeterM18 commented Jan 6, 2023

I'm fuzzy on just what debugging subprocesses entails. Does that involve splitting the debugger to follow each of the subprocesses? If so, check out how Eclipse with Pydev handles the kind of multiprocessing code VS Code can't. It just steps through it as if it were one process. Maybe not ideal if someone needs to debug interacting threads, but more than covers my, and I suspect many people's, use cases.

@int19h
Copy link
Contributor

int19h commented Jan 6, 2023

debugpy itself supports this; it just needs to be wired on Jupyter side of things.

@PeterM18
Copy link
Author

PeterM18 commented Jan 6, 2023

That's good to know! Any suggestions on how I could get this to work?

@int19h
Copy link
Contributor

int19h commented Jan 6, 2023

I can't think of any obvious workaround here given that you don't get access to the debug config to set "subProcess": false to ignore the child processes, unfortunately. It would require changing the code of vscode-jupyter extension that's referenced in the issue comments there, and then building your own local version of the extension VSIX with the fix.

@PeterM18
Copy link
Author

PeterM18 commented Jan 6, 2023

Thanks for letting me know. Out of my wheelhouse.

@matthiasgeihs
Copy link

I can't think of any obvious workaround here given that you don't get access to the debug config to set "subProcess": false to ignore the child processes, unfortunately. It would require changing the code of vscode-jupyter extension that's referenced in the issue comments there, and then building your own local version of the extension VSIX with the fix.

@int19h, any chance debug configurations for cell debugging will be made modifiable in the future?

@karthiknadig
Copy link
Member

@matthiasgeihs You could make a feature request to provide configurability on the Jupyter extension (https://github.com/microsoft/vscode-jupyter)

/cc @rebornix @DonJayamanne

@zaheeruddinfaiz
Copy link

this worked for me
thanks @int19h

@milosacimovic
Copy link

zaheeruddinfaiz 's solution no longer works since init.py does not contain _config in it

@cholojuanito
Copy link

zaheeruddinfaiz 's solution no longer works since init.py does not contain _config in it

It's located in debugpy/server/api.py like the comment says.

@imskull
Copy link

imskull commented May 9, 2024

Changing num_workers to 0 when you are creating DataLoader, it woks for me.

@asantos-6
Copy link

Changing num_workers to 0 when you are creating DataLoader, it woks for me.

This worked for me, thanks!

@xlnn
Copy link

xlnn commented Aug 15, 2024

Try reinstalling your extension. This is a known error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants