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 摘要。