process.is_alive() method

The process.is_alive() method of Python returns whether a process corresponding to the Process instance is alive or not. The Python example prints the return value of is_alive() method while a process is running as well as when it has exited.

Process Updated 3 Feb 2019 1 min read

Method Name

is_alive

Method Signature

is_alive()

Returns

bool

True – If the process is alive

Fale – If the process is not alive

Parameters

Not Applicable

Method Overview

  • Returns the process status corresponding to a Process instance (whether the process is alive or not).

Example

python
import multiprocessing as multiproc

            import time

def processFunction(messageQueue):

                for i in range(1, 10):

                    messageQueue.put("Message from Child Process")

                    time.sleep(1)

if __name__ == "__main__":

                multiproc.set_start_method("fork")

    messageQueue = multiproc.Queue()

                childProcess = multiproc.Process(target=processFunction, args=(messageQueue,))

    childProcess.start()

                print("The child process is alive:%s"%childProcess.is_alive())

                childProcess.join()

                print("The child process is alive:%s"%childProcess.is_alive())

                print("Parent process exiting")

Output

Output
The child process is alive:True

The child process is alive:False

Parent process exiting