I'm using multiprocessor.Pool
to parallelize processing some files. The code waits for a file to be received, then sends that file to a worker using Pool.apply_async
, which then processes the file.
This code is supposed to be always running, therefore I don't ever close the pool. This however causes the pool to consume a lot of memory over time.
The code is something like this:
if __name__ == "__main__":
with Pool(processes=PROCESS_COUNT) as pool:
while True:
f = wait_for_file()
pool.apply_async(process_file, (f,))
How can I prevent high memory usage from happening without closing the pool?