'Python3 multiprocessing and priority queue

i have input data that can be divided to two different options, let's call them "a" and "b". Depending on the chosen option my programm should do different things, options marked with "a" is more important than "b" and they can't run at the same time, so when input data classified as "a" i want to check is there active "b" process and if yes kill it and run "a" process instead and once "a" process is completed, run "b" process again. Any advises how to do this?



Solution 1:[1]

If you can't run multiple processes at the same time, then you don't need multiprocessing, so I'll assume you can run multiple A tasks and multiple B tasks at once, just not both at the same time.

The best way would be to have a controller process, an A process, and a B process(es). The B process pauses at regular intervals and check for a stop signal in its pipe using empty(). If not empty, then the process maybe saves its work terminates.

https://docs.python.org/3/library/multiprocessing.html

You could also try to send a signal directly to the process if the above is unacceptable for some reason, but I'm very wary of sending wild SIGTERMs.

https://docs.python.org/3/library/signal.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex Weavers