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

multiprocessing.Process.is_alive() incorrect if waitpid() was executed concurrently to it #92881

Open
ElectronicRU opened this issue May 17, 2022 · 0 comments
Labels
type-bug

Comments

@ElectronicRU
Copy link

@ElectronicRU ElectronicRU commented May 17, 2022

Bug report
As per title. In my case I triggered the os.waitpid() using psutil library, but easily reproducible using os.waitpid, too.

Reproduction:

Python 3.9.5 (default, Nov 18 2021, 16:00:48) 
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from multiprocessing import Process
>>> import os
>>> import time
>>> p = Process(target=time.sleep, args=(10,))
>>> p.start(); os.waitpid(p.pid, 0)
(17587, 0)
>>> p.is_alive()
True
>>> p.join() # Returns immediately
>>> 

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

  • CPython versions tested on: 3.9.5, but main version seems affected
  • Operating system and architecture: x64 Ubuntu Linux
@ElectronicRU ElectronicRU added the type-bug label May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug
Projects
None yet
Development

No branches or pull requests

1 participant