Skip to content

Commit

Permalink
Translate psutil.NoSuchProcess to OsError(errno.ESRCH)
Browse files Browse the repository at this point in the history
  • Loading branch information
fizyk committed May 13, 2021
1 parent eb087cc commit d0211e5
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/mirakuru/kill.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import errno
import os
from typing import List

Expand All @@ -12,10 +13,14 @@
if psutil:

def killpg(pid: int, sig: int) -> None:
process = psutil.Process(pid)
children: List[psutil.Process] = process.children(recursive=True)
for child in children:
child.send_signal(sig)
psutil.wait_procs(children, timeout=30)
process.send_signal(sig)
process.wait(timeout=30)
"""Custom killpg implementation for Windows."""
try:
process = psutil.Process(pid)
children: List[psutil.Process] = process.children(recursive=True)
for child in children:
child.send_signal(sig)
psutil.wait_procs(children, timeout=30)
process.send_signal(sig)
process.wait(timeout=30)
except psutil.NoSuchProcess as exc:
raise OSError(errno.ESRCH, exc.msg) from exc

0 comments on commit d0211e5

Please sign in to comment.