ipython / ipython/ipykernel

Should kernel restart interrupt running code?

未关闭
#462 9 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
734
派生
412
平均合并
1 天 5 小时
30 天内合并 PR
8

描述

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

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。