在我每次运行以下代码段时,ThreadPoolExecutor
不会执行该功能。终端上什么也没打印。
def get_route_data(itinerary):
route_id , src , dest , trip_type , onward_date_str , return_date_str , num_adult, num_child, num_infant , cabin_class = itinerary['ROUTE_ID'], itinerary['SRC'], itinerary['DEST'], itinerary['TRIP_TYPE'], itinerary['ONWARD_JOURNEY_DATE'], itinerary['RETURN_JOURNEY_DATE'], itineraryr['NUM_ADULT'], itinerary['NUM_CHILD'], itinerary['NUM_INFANT'], itinerary['CABIN_CLASS']
print(route_id , src , dest , trip_type , onward_date_str , return_date_str , num_adult, num_child, num_infant , cabin_class)
print(threading.current_thread())
time.sleep(2)
def dummy_func(itenary_df, NUM_WORKERS):
itinerary_list = itenary_df.to_dict('records')
with concurrent.futures.ThreadPoolExecutor(max_workers=NUM_WORKERS) as executor:
executor.map(get_route_data, itinerary_list)
但是,如果我将get_route_data
更改为-
get_route_data(itinerary):
print(itinerary)
print(threading.current_thread())
time.sleep(2)
itinerary
被打印在控制台上。
我不明白为什么会这样以及如何解决。