Skip to content

Commit

Permalink
fix: replace a few try-except cases with suppress
Browse files Browse the repository at this point in the history
  • Loading branch information
tysmith committed Jan 11, 2025
1 parent 91e6720 commit b327626
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/ffpuppet/process_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ def _last_modified(scan_dir: Path) -> float | None:
Returns:
Last modified date or None if no files are found.
"""
try:
with suppress(ValueError):
return max(x.stat().st_mtime for x in scan_dir.glob("**/*.gcda"))
except ValueError:
return None
return None


def _safe_wait_procs(
Expand Down Expand Up @@ -141,17 +140,13 @@ def cpu_usage(self) -> Generator[tuple[int, float]]:
"""
procs = self.processes()
for proc in procs:
try:
with suppress(AccessDenied, NoSuchProcess):
proc.cpu_percent()
except (AccessDenied, NoSuchProcess): # pragma: no cover
continue
# psutil recommends at least '0.1'.
sleep(0.1)
for proc in procs:
try:
with suppress(AccessDenied, NoSuchProcess):
yield proc.pid, proc.cpu_percent()
except (AccessDenied, NoSuchProcess): # pragma: no cover
continue

def dump_coverage(self, timeout: int = 15, idle_wait: int = 2) -> bool:
"""Signal processes to write coverage data to disk. Running coverage builds in
Expand Down

0 comments on commit b327626

Please sign in to comment.