When I try to do some parallel Computing in a loop,
from pathos.multiprocessing import ProcessingPool as Pool
def add(x,y):
return x+y
for i in range(10):
pool = Pool(4)
x = [0,1,2,3]
y = [4,5,6,7]
pool.map(add, x, y)
pool.close()
pool.join()
it returns errors:
ValueError: Pool not running
The only way I can find is:
for i in range(10):
pool = Pool(4)
pool.restart()
x = [0,1,2,3]
y = [4,5,6,7]
pool.map(add, x, y)
pool.close()
pool.join()
I expected I can re-assign a new pool in each iteration, but it seemed not to work. What happened?
I'm the
pathos
author. Inpathos
, aPool
is a singleton, so when you close the pool... instantiating a newPool
actually just gives you the closed pool. There is, however,restart
andclear
. I think you probably are looking forclear
. So, afterjoin
addclear()
-- then the instantiation of the new pool will be as you expect.