I'm wondering whether there's a native implementation in the multiprocessing module that would allow me to store running processes in a list-based structure and whenever a processes is finished with execution It's automatically removed from the list.
In code It'd look like this:
from multiprocessing import process
pool = [] # This data structure needs to prune non-running processes
class A(Process):
def run():
pass
for i in range(0, 10):
worker = A().start()
pool.append(worker)
# So if I want to iterate the pool now, It should only contain the alive processes
Another way to manage this would be to keep a dictionary:
pool = {
processId: processObject
}
And then get the active process ids using psutil:
current_process = psutil.Process()
children = current_process.children(recursive=False)
However, what'd be the size of the object inside the dictionary once the process dies?