Different child termination behavior during Kernel shutdown on Posix and Windows systems
維護者通常 2 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 35/100
- Issue 類型
- 功能
- 描述清晰度
- 基本清楚
- 活躍度
- 停滯
- 技術堆疊
- python
研究方向
從 ipykernel/kernelbase.py 的 1216-1227 行附近開始,追蹤 Kernel 關閉期間如何使用 _process_children()。比較 POSIX 程序群組篩選與 Windows 子程序路徑,並評估提議的執行個體層級設定。當能夠支援所需的自訂 Kernel 生命週期,同時保留現有預設行為時,即表示完成。
由索引模型根據 Issue 內容生成。
描述
Hello,
I've developed a custom Kernel inheriting from the IPython Kernel. This Kernel initiates a child process, and I aim to manage this process' lifecycle independently of the Kernel's shutdown workflow. To achieve this independence, I start the child process as a new process group. This approach functions as expected in POSIX systems, as the IPython Kernel verifies if the kernel process group is distinct from the child process group. However, a divergence in behavior arises when attempting the same workflow on Windows. This discrepancy stems from the IPython Kernel's behavior of returning all children of the Kernel process and subsequently sending SIGTERM signals to them. Please refer:
https://github.com/ipython/ipykernel/blob/main/ipykernel/kernelbase.py#L1218:L1227 and https://github.com/ipython/ipykernel/blob/main/ipykernel/kernelbase.py#L1216:L1217
I understand that it is not straightforward to determine the process group equivalence in Windows OS without using lower-level win32 APIs but this difference in behavior is causing issues in my custom kernel workflows.
Can I achieve my requirements without having to make any changes to the IPython Kernel? My proposed solution involves introducing an instance-level variable in the base Kernel class, which, if set to False, ensures that the Kernel refrains from terminating child processes by default during Kernel shutdown.
Here's a potential implementation:
self.terminate_all_children: bool = True # Set to true by default to maintain backward-compatibility
This variable is then checked in the _process_children() method to determine whether to process the children or not.
kernel_process = psutil.Process()
all_children = kernel_process.children(recursive=True)
process_group_children = []
if not self.terminate_all_children:
return process_group_children
else:
if os.name == "nt":
return all_children
kernel_pgid = os.getpgrp()
for child in all_children:
try:
child_pgid = os.getpgid(child.pid)
except OSError:
pass
else:
if child_pgid == kernel_pgid:
process_group_children.append(child)
return process_group_children
By setting terminate_all_children to False in the subclass, I ensure that the IPython Kernel doesn't terminate the child process by default when Kernel shutdown is initiated.
I'd appreciate your thoughts on this proposed solution. If it aligns with your expectations, I'm prepared to submit a PR. Thank you in advance!
- 主要語言
- Python
- 星號
- 734
- 分支
- 411
- 平均合併
- 1 天 11 小時
- 30 天內合併 PR
- 12
環境準備
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
ipython/ipykernel 的其他 Issue
-
難度 1/5 1 小時以內 新手友好度 72/100
維護者通常 2 天內回覆
-
難度 4/5 3-5 天 新手友好度 48/100
維護者通常 2 天內回覆
-
難度 4/5 3-5 天 新手友好度 68/100
ipython/ipykernel#1554 · 1 則留言 ·
維護者通常 2 天內回覆
-
Interrupt on swallowed `KeyboardInterrupt` exceptions (`SIGINT`) when pressing twice (within 5 seconds)可能重新可做 @Carreau 於 33 天前認領,目前沒有進行中的 PR。 未關閉
ipython/ipykernel#1550 · 1 則留言 · 1 個 reaction · 已指派 1 人 ·
維護者通常 2 天內回覆
-
難度 3/5 1-2 天 新手友好度 66/100
維護者通常 2 天內回覆
查看 ipython/ipykernel 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 88/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 84/100
spec-kitty/spec-kitty#5319 ·
維護者通常 1 天內回覆
-
backend::vllm diffusion multimodal
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 84/100
openai/openai-agents-python#5229 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 84/100
維護者通常 1 天內回覆