with futures.ThreadPoolExecutor(max_workers=40) as executor:
future_to_search_suspicious = dict()
for index, company in companies.iterrows():
future = executor.submit(search_suspicious_around_company, company)
future_to_search_suspicious[future] = company
for future in futures.as_completed(future_to_search_suspects):
company = future_to_search_suspicious[future]
if future.exception() is not None:
warn("{} raised an exception: {}".format(company["cnpj"],
future.exception()))
elif future.result() is not None:
write_suspicious_info(future.result(), company["cnpj"])
def search_suspicious_around_company(company):
After Change
:param companies: pandas dataframe.
rows = companies.to_dict("records")
total = len(rows)
count = 0
with Pool(processes=4) as pool:
for company in pool.imap(search_suspicious_around_company, rows):
count += 1