Python Multiprocess Pool. How to exit the script when one of the worker process determines no more work needs to be done?

You can use callbacks from Pool.apply_async. Something like this should do the job for you. from multiprocessing import Pool def part_crack_helper(args): solution = do_job(args) if solution: return True else: return False class Worker(): def __init__(self, workers, initializer, initargs): self.pool = Pool(processes=workers, initializer=initializer, initargs=initargs) def callback(self, result): if result: print(“Solution found! Yay!”) self.pool.terminate() def do_job(self): for … Read more