Skip to content

Process.wait(reap=True) parameter #2710

@giampaolo

Description

@giampaolo

Summary

  • OS: all (but only functional on POSIX)
  • Type: core

Description

When we do psutil.Process.wait(), we also implicitly reap the process. That means that we get the exit code from it, and the subsequent calls to os.waitpid() will not return it anymore. That is OK when we use psutil.Process class, since the exit code is cached and always returned. But a possible use case is to spawn multiple processes with subprocess.Popen classes, and then wait for them to finish with psutil.wait_procs(). In this case psutil.Process.wait() will "steal" the exit code of the subprocess.Popen instances. They can still be waited on, but they will have a status set to 0.

Proposal: add a new reap=True parameter. When False, we will not use os.waitpid() to check for process termination.

Note: on Windows this would be a no-op, since GetExitCodeProcess is able to return the status multiple times.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions