I'm using python's multiprocessing
module to handle a number of functions concurrently. Each spawned-process' function gets some initial input arguments, and a Pipe
connection to send its results back. For various reasons, I must use individual processes like this, i.e. tools like Pool.map_async()
-methods are off the table.
Occasionally, I need to terminate a process which takes too long to finish.
According to the Process documentation:
Warning: If this method is used when the associated process is using a pipe or queue then the pipe or queue is liable to become corrupted and may become unusable by other process. Similarly, if the process has acquired a lock or semaphore etc. then terminating it is liable to cause other processes to deadlock.
I'm not worried about the first part, as each process gets their own pipe object, but how do I determine if a process has 'acquired a lock or semaphore', and/or terminate in a way that's safe for the remainder of my program?