ThreadingPoolExecutor problem in appending the result to a list

Viewed 110

I have a list of 4500+ stock symbols and what I am trying to do is pull data for every symbol and call a function which returns True or False. However, this process is fairly slow so I am trying to implement threading for the operation.

results = []
def thread_function(ticker):
    df = pull_data(ticker)
    return capitulation_tester(df) # returns true or false 

with concurrent.futures.ThreadPoolExecutor(max_workers=15) as executor:
    futures = {executor.submit(thread_function, ticker): ticker for ticker in tickers}
    for future in concurrent.futures.as_completed(futures):
        fut = futures[future]
        try:
            results.append(future.result())
        except Exception as exc:
            print('%r generated an exception: %s' % (fut, exc))

After the code is finished, I get no results in the list even though running the code normally without threading returns results.

0 Answers
Related