I am running multiprocessing to shorten my optimization time for multi periods.
Before I was using for loop, which is fast when my data is not large.
for date in DatesOpt:
x = X.loc[X['Date'] == np.int(date)].drop('Date',1)
f = F.loc[F['Date'] == np.int(date)].drop('Date',1)
d = D.loc[D['Date'] == np.int(date)].drop('Date',1)
r = R.loc[R['Date'] == np.int(date)].drop('Date',1)
optimize(date,x,f,d,r)
The optimize function outputs the optimized result to a csv file.
However, when I changed it to
if __name__=='__main__':
pool = mp.Pool(mp.cpu_count()-1)
for date in DatesOpt:
x = X.loc[X['Date'] == np.int(date)].drop('Date',1)
f = F.loc[F['Date'] == np.int(date)].drop('Date',1)
d = D.loc[D['Date'] == np.int(date)].drop('Date',1)
r = R.loc[R['Date'] == np.int(date)].drop('Date',1)
pool.apply_async(optimize,args=(date,x,f,d,r,))
print('Waiting for all subprocesses done')
pool.close()
print('Pool Closed')
pool.join()
print('All subprocess done.')
everything just stops at the "Pool Closed" output and the optimizer never ends.
Is there any problem with this code?