ipython / ipython/ipykernel

Should kernel restart interrupt running code?

Aberta
#462 9 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Python
Estrelas
734
Forks
412
Merge médio
1d 5h
PRs com merge (30d)
8

Descrição

I'm not sure if this is a bug or intended behavior. AFAICT, if a user restarts a kernel while the interpreter is actively processing, no SIGINT is sent to the interpreter process, and eventually the process is SIGKILL'd. This can lead to `atexit` handlers never running.

This is causing issues in dask, where we use atexit handlers to ensure remote resources are reclaimed.

Here's a reproducer. Paste this into a notebook cell, run, then restart the kernel before the cell finishes executing.

```python
import atexit
import os
import time

with open("temp-file", "w") as f:
f.write("This file should be deleted by the exit handler")

@atexit.register
def exit_handler():
os.unlink("temp-file")

time.sleep(1000)

# Restart the kernel, `temp-file` should be deleted but isn't.
# If you interrupt, then restart, then `temp-file` is deleted
```

If you instead interrupt the kernel then restart it, everything is cleaned up properly. Is this intended behavior (and the issue is user workflow, rather than a possible bug)?

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.