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

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

Open rk-exxec opened this issue 7 months ago • 3 comments

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.

  • VS Code Version: 1.91.1
  • OS Version: Win 10 - 10.0.19045 Build 19045

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)

rk-exxec avatar Jul 24 '24 12:07 rk-exxec