Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip so-called plot processes that are parents of others #418

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 46 additions & 22 deletions src/plotman/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,28 +137,52 @@ def get_running_jobs(logroot, cached_jobs=()):
jobs = []
cached_jobs_by_pid = { j.proc.pid: j for j in cached_jobs }

for proc in psutil.process_iter():
# Ignore processes which most likely have terminated between the time of
# iteration and data access.
with contextlib.suppress(psutil.NoSuchProcess, psutil.AccessDenied):
if is_plotting_cmdline(proc.cmdline()):
if proc.pid in cached_jobs_by_pid.keys():
jobs.append(cached_jobs_by_pid[proc.pid]) # Copy from cache
else:
with proc.oneshot():
parsed_command = parse_chia_plots_create_command_line(
command_line=proc.cmdline(),
)
if parsed_command.error is not None:
continue
job = Job(
proc=proc,
parsed_command=parsed_command,
logroot=logroot,
)
if job.help:
continue
jobs.append(job)
with contextlib.ExitStack() as exit_stack:
processes = []

for process in psutil.process_iter():
# Ignore processes which most likely have terminated between the time of
# iteration and data access.
with contextlib.suppress(psutil.NoSuchProcess, psutil.AccessDenied):
exit_stack.enter_context(process.oneshot())
if is_plotting_cmdline(process.cmdline()):
processes.append(process)

# https://github.com/ericaltendorf/plotman/pull/418
# The experimental Chia GUI .deb installer launches plots
# in a manner that results in a parent and child process
# that both share the same command line and, as such, are
# both identified as plot processes. Only the child is
# really plotting. Filter out the parent.

pids = {process.pid for process in processes}
ppids = {process.ppid() for process in processes}
wanted_pids = pids - ppids

wanted_processes = [
process
for process in processes
if process.pid in wanted_pids
]
Comment on lines +158 to +166
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nit but a good nit: add a small comment saying why this is necessary, maybe even reference this PR, as it may not be clear the reason this is necessary

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, added. Does it read well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superb 👨‍🍳 💋


for proc in wanted_processes:
if proc.pid in cached_jobs_by_pid.keys():
jobs.append(cached_jobs_by_pid[proc.pid]) # Copy from cache
else:
with proc.oneshot():
parsed_command = parse_chia_plots_create_command_line(
command_line=proc.cmdline(),
)
if parsed_command.error is not None:
continue
job = Job(
proc=proc,
parsed_command=parsed_command,
logroot=logroot,
)
if job.help:
continue
jobs.append(job)

return jobs

Expand Down