ipython / ipython/ipykernel

Should kernel restart interrupt running code?

Abierto
#462 9 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
734
Forks
412
Merge medio
1 d 5 h
PR fusionados (30 d)
8

Descripción

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)?

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.