-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
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.