Environment:
Python 3 and Windows 10
I have some cpu intensive code that currently runs through all rows in a data-set and computes something for each row. It currently takes about 1 minute to do around 10k rows and I think this can can dramatically reduced with a process pool (it doesn't matter what order the results are computed in).
I am relatively new to python programming and after some research, futures seems ideal. Doing something like:
with futures.ProcessPoolExecutor() as executor:
my_futures = [executor.submit(my_function,row) for row in my_data]
..do stuff with results
The problem is that in windows it seems that I need to run this code in the main module?
if __name__ == '__main__':
Due to recursive calls (and yes I managed to crash my computer like others have :) )
My code is in a class called by another class so it is not under the main module. Without rewriting everything (and making the code somewhat clunky) I don't see a way to sort this. Is there a way around this or another library for concurrent processes which can be used?