microsoft / vscode-jupyter

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

Jupyter Notebook Kernel crash during asyncio execution - error message displays in previous cell ouput #15893

Open rk-exxec opened 1 month ago

rk-exxec commented 1 month ago

Does this issue occur when all extensions are disabled?: No, Jupyter and Python need to be enabled for the code to run. But I did a bisect and cant identify an extension that would be responsible. The crash only occurs occasionally.

grafik

The second cell causes a kernel crash in the "fit" cell while executing asyncio futures. The crash message shows in the previous cell "init" output, but only when "Execute all" is used.

Steps to Reproduce:

  1. Run two cells in a row with "Execute all"
  2. the second cell causes a kernel crash
  3. observe error message in first cell output

I wasn't able to create a minimal reproducible example, because the crash only happens in my specific case and not every time. Here is the code for the crashing cell:

def background(f):
    def wrapped(*args, **kwargs):
        return asyncio.get_event_loop().run_in_executor(None, f, *args, **kwargs)
    return wrapped

@background
def async_fun(file):
    try:
        # something that causes a kernel crash
    except Exception as e:
            print(str(e), traceback.format_exc())
            print(file)

futures = list()

sem = asyncio.Semaphore(4)
for file in sources:
    async with sem:
        futures.append(async_fun(file))

res = await asyncio.gather(*futures)
VSCodeTriageBot commented 1 month ago

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.91.1. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

rk-exxec commented 1 month ago

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.91.1. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

It was a typo. I'm using the newest version.

DonJayamanne commented 1 month ago

Thanks for filing this issue. I'm unable to replicate this issue. Here's the code I'm using to run in the second cell with async io and kernel crash. I'll send a custom VSIX that will contain some additional logging, hopefully that will help.

import asyncio

sources = ['']

def background(f):
    def wrapped(*args, **kwargs):
        return asyncio.get_event_loop().run_in_executor(None, f, *args, **kwargs)
    return wrapped

@background
def async_fun(file):
    try:
        # something that causes a kernel crash
        import IPython
        app = IPython.Application.instance()
        app.kernel.do_shutdown(True)
    except Exception as e:
        print(str(e), traceback.format_exc())
        print(file)

futures = list()

sem = asyncio.Semaphore(4)
for file in sources:
    async with sem:
        futures.append(async_fun(file))

res = await asyncio.gather(*futures)