ipython / ipython/ipykernel

How to signal shutdown by user code?

未關閉
#1,151 7 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
734
分支
412
平均合併
1 天 5 小時
30 天內合併 PR
8

描述

I'm implementing a kernel by inheriting from `ipykernel.kernelbase.Kernel`, as described at [Making simple Python wrapper kernels](https://jupyter-client.readthedocs.io/en/latest/wrapperkernels.html).

My `do_execute` method passes code to an external interpreter implemented in a Python module, and it is possible that this code includes an instruction to shut down the interpreter, comparable to `sys.exit(0)` in Python. When that happens, the interpreter raises an exception.

Because after that code the interpreter is no longer usable, I want to catch that exception and in response initiate a kernel shutdown. Unfortunately, I wasn't able to figure out how to do so.

Is it possible to initiate a kernel shutdown from within the kernel? If yes, how?

If not, what is the recommended way to deal with code which shuts down the interpreter? Detecting that from the code might be impossible to do correctly. And even if I could do it, I would still have to initiate shutdown from within `do_execute`.

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。