[issue30976] multiprocessing.Process.is_alive can show True for dead processes

Gareth Rees report at bugs.python.org
Thu Jul 20 13:13:20 EDT 2017


Gareth Rees added the comment:

This is a race condition — when os.kill returns, that means that the signal has been delivered, but it does not mean that the subprocess has exited yet. You can see this by inserting a sleep after the kill and before the liveness check:

    print(proc.is_alive())
    os.kill(proc.pid, signal.SIGTERM)
    time.sleep(1)
    print(proc.is_alive())

This (probably) gives the process time to exit. (Presumably the psutil.pid_exists() call has a similar effect.) Of course, waiting for 1 second (or any amount of time) might not be enough. The right thing to do is to join the process. Then when the join exits you know it died.

----------
nosy: +gdr at garethrees.org

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30976>
_______________________________________


More information about the Python-bugs-list mailing list