问题描述
我想使用ThreadPoolExecutor
在参数列表上运行多个函数。
当我使用以下代码时,这些函数将使用相同的参数重复出现,并且代码将无限期地运行。
thread_count = 0
with concurrent.futures.ThreadPoolExecutor(max_workers=workers) as executor:
for i,itinerary_dict in enumerate(itinerary_list):
results = []
for _ in range(
parser.getboolean('other','goibiboFlag')
+ parser.getboolean('other','mmtFlag')
+ parser.getboolean('other','emtFlag')
):
if parser.getboolean('other','goibiboFlag'):
if (
itinerary_dict['WEBSITE'] == 'ALL'
or itinerary_dict['WEBSITE'].lower().strip() == 'goibibo'
):
itinerary_dict['t_num'] = thread_count
results.append(
executor.submit(
goibibo.get_route_data,itinerary_dict,params
)
)
thread_count += 1
if parser.getboolean('other','mmtFlag'):
if (
itinerary_dict['WEBSITE'] == 'ALL'
or itinerary_dict['WEBSITE'].lower().strip() == 'mmt'
):
itinerary_dict['t_num'] = thread_count
results.append(
executor.submit(
mmt.get_route_data,'emtFlag'):
if (
itinerary_dict['WEBSITE'] == 'ALL'
or itinerary_dict['WEBSITE'].lower().strip() == 'emt'
):
itinerary_dict['t_num'] = thread_count
results.append(
executor.submit(
emt.get_route_data,params
)
)
thread_count += 1
for f in concurrent.futures.as_completed(results):
error_logger.info(f)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)