I want to run multiple functions on a list of arguments using ThreadPoolExecutor.
When I use the following code, the functions are getting repeated with the same arguments and the code is running indefinitely.
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, itinerary_dict, params
)
)
thread_count += 1
if parser.getboolean('other', '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, itinerary_dict, params
)
)
thread_count += 1
for f in concurrent.futures.as_completed(results):
error_logger.info(f)