fix(cli): keep child cleanup working on Windows
_cleanup_children() called os.killpg unconditionally — Windows doesn't have killpg as an attribute on os, so the call raised AttributeError (not caught by the existing OSError-family handler) and aborted cleanup. Guard with hasattr(os, "killpg") and fall back to os.kill(pid, SIGTERM) on platforms without process-group APIs. Closes #226. Refs #110. Co-authored-by: gujishh <baiaoshh@163.com>
This commit is contained in:
@@ -63,7 +63,10 @@ def _cleanup_children() -> None:
|
|||||||
pids = list(_child_pids)
|
pids = list(_child_pids)
|
||||||
for pid in pids:
|
for pid in pids:
|
||||||
try:
|
try:
|
||||||
os.killpg(os.getpgid(pid), signal.SIGTERM)
|
if hasattr(os, "killpg"):
|
||||||
|
os.killpg(os.getpgid(pid), signal.SIGTERM)
|
||||||
|
else:
|
||||||
|
os.kill(pid, signal.SIGTERM)
|
||||||
except (ProcessLookupError, PermissionError, OSError):
|
except (ProcessLookupError, PermissionError, OSError):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user