feat: 通过匿名管道实现父进程死亡检测,替代轮询方案

- worker.go: 为每个子进程创建 death pipe,Go 持有写端
- __init__.py: run() 中监听管道读端 EOF,Go 退出时立即终止子进程
- 解决 Ctrl+C / panic / SIGKILL 等场景下 Python worker 变成孤儿进程的问题
- Python 包版本升至 0.1.2
This commit is contained in:
2026-04-14 13:49:33 +08:00
parent b390effd8e
commit 39517dc5fc
4 changed files with 48 additions and 6 deletions

View File

@@ -385,6 +385,17 @@ def run():
server.bind(sock_path)
server.listen(64)
# Death pipeGo 持有写端,本进程阻塞读端。
# Go 进程消亡任何原因Ctrl+C、panic、SIGKILL时写端自动关闭read() 立即返回 EOF。
death_fd = int(os.environ.get("GOBRIDGE_DEATH_FD", "0"))
if death_fd:
def _watch_death_pipe():
with os.fdopen(death_fd, "rb") as f:
f.read(1) # 阻塞直到 Go 关闭写端EOF
server.close()
os._exit(0)
threading.Thread(target=_watch_death_pipe, daemon=True).start()
try:
while True:
try:

View File

@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "gobridge"
version = "0.1.1"
version = "0.1.2"
description = "Python 端库,配合 Go 侧 gobridge 使用"
requires-python = ">=3.10"