mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-30 11:52:04 +00:00
fix: satisfy ruff encoding + windows-footgun lints for cgroup reaper
- read_text(encoding='utf-8') (PLW1514) - # windows-footgun: ok on signal.SIGKILL — module is Linux-only (reads /proc, /sys/fs/cgroup; runs from a systemd unit) - test lambda accepts the new encoding kwarg
This commit is contained in:
parent
86ec979f66
commit
c23f394eb8
2 changed files with 4 additions and 4 deletions
|
|
@ -24,7 +24,7 @@ from pathlib import Path
|
|||
def _own_cgroup_path() -> str | None:
|
||||
"""Return the cgroup v2 path for the calling process, or None."""
|
||||
try:
|
||||
text = Path("/proc/self/cgroup").read_text()
|
||||
text = Path("/proc/self/cgroup").read_text(encoding="utf-8")
|
||||
except OSError:
|
||||
return None
|
||||
match = re.search(r"^0::(.+)$", text, re.MULTILINE)
|
||||
|
|
@ -36,7 +36,7 @@ def _own_cgroup_path() -> str | None:
|
|||
def _read_cgroup_pids(cgroup_path: str) -> list[int]:
|
||||
procs_file = Path(f"/sys/fs/cgroup{cgroup_path}/cgroup.procs")
|
||||
try:
|
||||
raw = procs_file.read_text()
|
||||
raw = procs_file.read_text(encoding="utf-8")
|
||||
except OSError:
|
||||
return []
|
||||
pids: list[int] = []
|
||||
|
|
@ -63,7 +63,7 @@ def reap_cgroup(cgroup_path: str | None = None) -> int:
|
|||
if pid == own:
|
||||
continue
|
||||
try:
|
||||
os.kill(pid, signal.SIGKILL)
|
||||
os.kill(pid, signal.SIGKILL) # windows-footgun: ok — Linux-only (reads /proc, /sys/fs/cgroup; runs from a systemd unit)
|
||||
killed += 1
|
||||
except ProcessLookupError:
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class TestOwnCgroupPath:
|
|||
def _raise(_path):
|
||||
raise FileNotFoundError
|
||||
|
||||
monkeypatch.setattr(cgroup_cleanup.Path, "read_text", lambda self: _raise(self))
|
||||
monkeypatch.setattr(cgroup_cleanup.Path, "read_text", lambda self, *a, **k: _raise(self))
|
||||
assert cgroup_cleanup._own_cgroup_path() is None
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue