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