- Terminates the process corresponding to the process instance on which it was invoked.
- In Unix-like operating systems it uses SIGTERM signal to terminate the process.In Windows it uses TerminateProcess().
- It causes the child processes of the terminated process to become orphaned.
- After a process is terminated using terminate(), any data passing mechanisms held by the process like Queues, Pipes may become corrupt.
- If the process has acquired any synchronization objects this may cause a deadlock to other processes that were waiting on those synchronization objects.
import multiprocessing as multiproc
# Process function
for i in range(1,20):
print("Child:Populated the Queue with:%d"%i)
if __name__ == "__main__":
# Set the method for process creation
# Create a Queue
mq = multiproc.Queue()
childProc = multiproc.Process(target=pfunc,args=(mq,))
print("Parent:After child process has started")
# Terminate the child process
print("Parent:After terminate() on the child process")
# Join will return immediately as the process has been terminated already
print("Parent:Exit code of the child process on terminate():%d"%childProc.exitcode)
if childProc.is_alive() == True:
print(mq.get()) # Queue may be corrupt if process had encountered a terminate() call
Parent:After child process has started
Child:Populated the Queue with:1
Parent:After terminate() on the child process
Parent:Exit code of the child process on terminate():-1