我正在尝试将动态生成的日期变量列表传递到多进程池中。
当我从data_2_days()
请求特定日期时,多进程工作正常,但是如果我使用data_start_and_end()
生成字符串,则会得到:
ValueError:需要超过1个值才能解包
我认为返回的字符串用引号引起来,这就是导致问题的原因。
生成日期变量列表以传递到多进程池的最佳方法是什么?
谢谢
def data_start_and_end(start_date,end_date):
start_date = DateTime.strptime(start_date, '%Y-%m-%d')
end_date = DateTime.strptime(end_date, '%Y-%m-%d')
no_days = (end_date-start_date).days
date_str = "("
# date_end_str =
x = 0
while x <= no_days :
if x ==0:
date = start_date
if date.month < 10:
month_str = "0"+str(date.month)
else:
month_str = date.month
if date.day < 10:
day_str = "0"+str(date.day)
else:
day_str = date.day
date_str = date_str + "['"+ str(date.year) + "','" + str(month_str) + "','" + str(day_str) +"'],"
# print date_str
date = date + TimeDelta(days=1)
x=x+1
date_str = date_str[:-1] + ")"
print date_str
# dates =
return(date_str)
def data_2_days():
data = ( \
['2018','01','01'], \
['2018','01','02'])
return(data)
def figure_probs_mp(start_date,end_date):
data = ZZ_MP_data_lists.data_start_and_end(start_date,end_date)
pool = multiprocessing.Pool(36)
pool.map(figure_probs, data)
pool.close()
pool.join()
figure_probs_mp(start_date,end_date)