Skip to content

Commit

Permalink
Fix no-such-process error
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-eq committed Nov 20, 2024
1 parent 5c8b1c2 commit b449835
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/_ert/forward_model_runner/forward_model_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ async def _run(self) -> "AsyncGenerator[Start | Exited | Running | None]":
stderr=stderr,
env=self._create_environment(),
)
process = Process(proc.pid)

except OSError as e:
exited_message = self._handle_process_io_error_and_create_exited_message(
e, stderr
Expand All @@ -195,9 +195,9 @@ async def _run(self) -> "AsyncGenerator[Start | Exited | Running | None]":
exit_code = None

max_memory_usage = 0
fm_step_pids = {int(process.pid)}
fm_step_pids = {int(proc.pid)}
while exit_code is None:
(memory_rss, cpu_seconds, oom_score) = _get_processtree_data(process)
(memory_rss, cpu_seconds, oom_score) = _get_processtree_data(proc.pid)
max_memory_usage = max(memory_rss, max_memory_usage)
yield Running(
self,
Expand All @@ -223,9 +223,11 @@ async def _run(self) -> "AsyncGenerator[Start | Exited | Running | None]":
yield potential_exited_msg

return
fm_step_pids |= {
int(child.pid) for child in process.children(recursive=True)
}
with contextlib.suppress(NoSuchProcess):
proccess = Process(proc.pid)
fm_step_pids |= {
int(child.pid) for child in proccess.children(recursive=True)
}

ensure_file_handles_closed([stdin, stdout, stderr])
exited_message = self._create_exited_message_based_on_exit_code(
Expand Down Expand Up @@ -438,7 +440,7 @@ def ensure_file_handles_closed(file_handles: Sequence[io.TextIOWrapper | None])


def _get_processtree_data(
process: Process,
pid: int,
) -> Tuple[int, float, Optional[int]]:
"""Obtain the oom_score (the Linux kernel uses this number to
decide which process to kill first in out-of-memory siturations).
Expand All @@ -460,21 +462,19 @@ def _get_processtree_data(
memory_rss = 0
cpu_seconds = 0.0
with contextlib.suppress(ValueError, FileNotFoundError):
oom_score = int(
Path(f"/proc/{process.pid}/oom_score").read_text(encoding="utf-8")
)
with (
contextlib.suppress(
ValueError, NoSuchProcess, AccessDenied, ZombieProcess, ProcessLookupError
),
process.oneshot(),
oom_score = int(Path(f"/proc/{pid}/oom_score").read_text(encoding="utf-8"))
with contextlib.suppress(
ValueError, NoSuchProcess, AccessDenied, ZombieProcess, ProcessLookupError
):
memory_rss = process.memory_info().rss
cpu_seconds = process.cpu_times().user
process = Process(pid)
with process.oneshot():
memory_rss = process.memory_info().rss
cpu_seconds = process.cpu_times().user

with contextlib.suppress(
NoSuchProcess, AccessDenied, ZombieProcess, ProcessLookupError
):
process = Process(pid)
for child in process.children(recursive=True):
with contextlib.suppress(
ValueError,
Expand Down

0 comments on commit b449835

Please sign in to comment.