Skip to content

Commit db9ff3a

Browse files
committed
Fix os.process typing issues
1 parent a48c6b5 commit db9ff3a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/e3/os/process.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@
5656
try:
5757
import psutil
5858
from psutil import Popen
59+
60+
has_psutil = True
5961
except ImportError: # defensive code
60-
from subprocess import Popen
62+
from subprocess import Popen # type: ignore
6163

62-
psutil = None
64+
has_psutil = False
6365

6466

6567
def subprocess_setup() -> None:
@@ -419,7 +421,7 @@ def add_interpreter_command(cmd_line: CmdLine) -> CmdLine:
419421
self.internal = Popen(self.cmds[0], **popen_args)
420422

421423
else:
422-
runs: list[subprocess.Popen] = []
424+
runs: list[Popen] = []
423425
for index, cmd in enumerate(self.cmds):
424426
if index == 0:
425427
stdin: int | IO[Any] = self.input_file.fd
@@ -609,15 +611,15 @@ def interrupt(self) -> None:
609611

610612
def is_running(self) -> bool:
611613
"""Check whether the process is running."""
612-
if psutil is None: # defensive code
614+
if not has_psutil: # defensive code
613615
# psutil not imported, use our is_running function
614616
return is_running(self.pid)
615617
else:
616618
return self.internal.is_running()
617619

618620
def children(self) -> list[Any]:
619621
"""Return list of child processes (using psutil)."""
620-
if psutil is None: # defensive code
622+
if not has_psutil: # defensive code
621623
raise NotImplementedError("Run.children() require psutil")
622624
return self.internal.children()
623625

@@ -838,7 +840,7 @@ def kill_process_tree(pid: int | Any, timeout: int = 3) -> bool:
838840
except psutil.NoSuchProcess: # defensive code
839841
pass
840842

841-
def on_terminate(p: str) -> None:
843+
def on_terminate(p: psutil.Process) -> None:
842844
"""Log info when a process terminate."""
843845
logger.debug("process %s killed", p)
844846

0 commit comments

Comments
 (0)