kill code-server with sudo kill

This commit is contained in:
CakeCN
2025-09-12 16:09:29 +08:00
parent 3d50c410bf
commit 5fb8eeecea

View File

@@ -205,9 +205,11 @@ class ChatManager:
return True # 已退出
try:
# 优雅:向进程组发 SIGTERM
os.killpg(pop.pid, signal.SIGTERM)
print("send SIGTERM to code-server")
subprocess.run(
["sudo", "kill", "-TERM", str(pop.pid)],
check=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
except ProcessLookupError:
return True
@@ -222,7 +224,11 @@ class ChatManager:
# 兜底:强杀进程组
try:
print("kill code-server")
os.killpg(pop.pid, signal.SIGKILL)
subprocess.run(
["sudo", "kill", "-KILL", str(pop.pid)],
check=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
except ProcessLookupError:
pass
finally: