microsoft / vscode-jupyter

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

Error: Direct kernel connection broken #1706

Closed GitForrest closed 2 years ago

GitForrest commented 4 years ago

Issue Type: Bug

Open any file.ipynb and attempt to run a cell.

print('hello')

expect output : hello

receive: 'Error: Direct kernel connection broken'instead with the following details.

Error: Direct kernel connection broken at getDisposedError (c:\Users\forresr2.vscode\extensions\ms-python.python-2020.8.103604\out\client\extension.js:24:684530) at f.P.handleCodeRequest (c:\Users\forresr2.vscode\extensions\ms-python.python-2020.8.103604\out\client\extension.js:48:467398) at c:\Users\forresr2.vscode\extensions\ms-python.python-2020.8.103604\out\client\extension.js:48:480019 at runMicrotasks () at processTicksAndRejections (internal/process/task_queues.js:85:5)

Extension version: 2020.8.103604 VS Code version: Code 1.48.2 (a0479759d6e9ea56afa657e454193f72aef85bd0, 2020-08-25T10:13:11.295Z) OS version: Windows_NT x64 10.0.17134

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz (4 x 2496)| |GPU Status|2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off_ok
webgl: enabled
webgl2: enabled| |Load (avg)|undefined| |Memory (System)|7.88GB (3.46GB free)| |Process Argv|| |Screen Reader|no| |VM|0%|
MJimitater commented 3 years ago

FYI I also noticed that I get this error "Error: Direct kernel connection broken", if I've got notebook_1 running a kernel_1 with GPU usage, and then I start notebook_2 with a different kernel_2 but also with GPU usage.

DonJayamanne commented 3 years ago

@MJimitater Does the issue repro in classic Jupyter?

MJimitater commented 3 years ago

@DonJayamanne yes, it seems I can reproduce in classic Jupyter in the browser - but the error message then changes to "Kernel Restarting The kernel appears to have died. It will restart automatically."

@MJimitater Does the issue repro in classic Jupyter?

MJimitater commented 3 years ago

@DonJayamanne Thanks for taking a look!!

  1. Here is my ipynb notebook and my debug file (zip) Note that the error occurs after executing cell 12; if I comment that cell out however, it works.
  2. This problem occurs in Jupyter classic as well as in insiders

I noticed how the kernel always throws this broken kernel connection error, when trying to enumerate through a Tensorflow Dataset holding close to 1 Million (1x1000) arrays. However, if I go down in size, then it works! Perhaps the error is linked to huge tf datasets?!

EDIT: From the last line of the debug output, I think my error is linked to this tensorflow issue.

EDIT 2: So I found out that my kernel always breaks if I run out of memory (see link to other tensorflow issue above). This was caused due to a massive tf dataset, that I enumerated through (in cell 12). Once this dataset held more than a certain amount of samples (in my case 2 million), then my kernel always broke. But once I reduced the size, it worked. Did anyone observe a similar reason?

I always kept running into this issue after training for many epochs in VSCode (Classic and Insiders). E.g. the issue always occured after epoch 112, 114, 144 (or something similar) when training for 200 epochs. BUT: running the code in Jupyter Notebook Classic (no VSCode) didn't throw the error during training.

DonJayamanne commented 3 years ago

Thanks, will try this at our end.

pmh722 commented 3 years ago

I encountered this same error. For me I believe it was caused by an out-of-memory error. Whenever I reproduce it and monitor system memory, RAM runs out right before the error.

As such I don't think the failure itself is a VS Code bug per se, at least in my use case. But it might be nice quality of life feature if VS Code could detect the OOM error and give a more informative error message.

To those who avoid this bug by running the same code outside VS Code... do you think it might be because VS Code takes up more RAM, leaving less available for your program?

FWIW I am running interactive python REPL in container.

ivanmkc commented 3 years ago

I had this issue and restarting didn't help. I tapped the kernel button in the top-right and noticed that it was using the system Python. I switched to my virtualenv Python and now it works as expected.

pranshuub commented 3 years ago

Just wondering any solution to this yet? @DonJayamanne

I've been having the same issue while trying to load a massive image dataset with landmarks(lazylist) into a numpy array.

Also i noticed something interesting. I tried splitting my dataset and saving half into a numpy array in one cell and then doing the same for the other half in a different cell into a different numpy array, so as to see if the kernel stops even when i'm not loading all of it into one array.

The total images are 2000 in number. When i was loading into one array it was stopping at around the 1300 mark. when i split the dataset, the first executed and loaded 1050 images completely into an array, but then the second cell stopped at around 170 and the kernel connection broke and didn't fill the second array fully.

Any help would be appreciated

DonJayamanne commented 3 years ago

@pranshuub thanks for reaching out, and I'm sorry you're running into this issue. Please could you test this in Jupyter as well, most have confirmed that this problem persists in Jupyter as well (though the memory restrictions are slightly different). Basically at this stage is a problem in classic Jupyter as well, and we're looking at providing better error messages.

jjungkim85 commented 3 years ago

I encountered an issue shows this error while using matplotlib.pyplot.imshow for numpy.ndarray.

In this case, the problem was caused by "Initializing libiomp5md.dll, but found libiomp5md.dll already initialized." and

I temporary solved it by adding

 import os
 os.environ['KMP_DUPLICATE_LIB_OK']='True'
aarsanjani commented 3 years ago

Same issue

blakefren commented 3 years ago

I was facing this issue, but was not loading a large dataset. Following #778, I had an "exit()" call which was causing the crash. Removing it fixed the issue.

DonJayamanne commented 3 years ago

Just wanted to check if anyone was still running into the same issues with the latest version of VS Code and Jpyter extension. We've addressed a lot of the related issues. If not, please do provide the following and I'll look into them:

rchiodo commented 2 years ago

Should be fixed now. Anybody else still hitting this problem, please comment/reopen.