-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
multiprocessing.Process.is_alive() incorrect if waitpid() was executed concurrently to it #92881
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
Comments
The reason of the bug is that in the try:
pid, sts = os.waitpid(self.pid, flag)
except OSError:
# Child process not yet created. See #1731717
# e.errno == errno.ECHILD == 10
return None However, when an
There's no way in that specific function to tell them apart without adding some extra state variables. Actually, it's more than just I can't think of a simple way to solve this issue, but this should at least be documented somewhere. |
I'm curious if folks have context on why the multiprocessing Process implementation is not thread safe ? subprocess was made thread safe a while back. I solved the problem for my usecase with the following snippet to synchronize the poll command. This doesn't address the global
|
Using I think this issue should just be closed. A documentation update might be worthwhile, but even that is tricky. There are many ways the user could interfere and it isn't obvious what to say or where the note should go. Just doing an See also #130895, which is a similar issue caused by a race condition. Although since it all goes through the high-level interface it can be fixed, at least in principle. |
Bug report
As per title. In my case I triggered the os.waitpid() using psutil library, but easily reproducible using os.waitpid, too.
Reproduction:
I understand it's something of a corner case; however, join() behaves correctly here, so we definitely have enough info about whether the process is alive.
By the looks of it, if the process has been already waited on,
poll()
Popen method in multiprocessing returns None, which is interpreted as the process being still alive.Your environment
The text was updated successfully, but these errors were encountered: