pythonmultithreadingmultiprocessingpoolemcee

Closing the multiprocessing after each parallel job


I am using multiprocessing library of python and also emcee which also uses different threads to implement MCMC. The problem is that even when I close the pool still it seems python uses the processors and slows down the cores and I have no idea what is the efficient way to release the cores after the job is done. Could anybody give me an idea of what I should do?
Update: My code has been already posted here.


Solution

  • Closing a Pool doesn't stop it from doing work, it just prevents new work items from being added to it:

    close()

    Prevents any more tasks from being submitted to the pool. Once all the tasks have been completed the worker processes will exit.

    So if you have a lot of queued tasks, closing the Pool won't make any difference in resource usage - all the workers will keep consuming those queued tasks until they're gone. If you want to basically abort all the work items immediately, you have to use pool.terminate:

    terminate()

    Stops the worker processes immediately without completing outstanding work. When the pool object is garbage collected terminate() will be called immediately.