diff --git a/src/plotman/job.py b/src/plotman/job.py index 39ccbb28..1c225ab9 100644 --- a/src/plotman/job.py +++ b/src/plotman/job.py @@ -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 + ] + + 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