How to terminate a process/ all processes in other process in python multiprocessing

hi i have created three processes and started .
now i want to kill all processes in one of the process based on a condition.

multiprocessing.current_process().terminate() gives me current process but how can i get all other processes .
global variable declaration is not working here

Howdy Saidesh,

if you want a process ‘B’ to be terminated by a process ‘A’, you could do the following:

Share a Queue between both (e.g. using a multiprocessing Manager), let ‘B’ push an arbitrary ‘lifeline’ object in said Queue during setup / initialization.

If, after that, process ‘A’ pops said ‘lifeline’ object from said Queue (and said Queue hereby becomes empty), process ‘B’ can detect this and interpret this as the terminate signal and terminate itself.

By this you can initiate the termination of process ‘B’ from process ‘A’.

If you e.g. want to be save against the hanging of process ‘A’ too, you also can use a ‘watchdog heartbeat’ put periodically into a ‘leaky bucket’ - via Queue / Pipe.

If you (really?) want to terminate other processes the hard way instead, you first have to tell us, under which OS (Windows, Linux, macOS?) this should work, as process handling is OS specific, as far as I know…

Cheers, Dominik