Open windowshopr opened 2 years ago
You have to create your pool in the if name == main.
@fmder Thanks! I tried that now, but same issue as when it all goes under the if __name__ == '__main__':
, in that it only appears to run 1 process, even with Pool()
not defining 1 worker. I don't understand why it's doing that.
If you put the process pool OUTSIDE the name == main, it runs multiple workers, but with that error. Inside, it only runs one process, confirmed by watching thread performance during both.
I guess as a bandaid, I replace this:
# Multiprocessing
pool = multiprocessing.Pool()
toolbox.register("map", pool.map)
...with this:
if __name__ == '__main__':
# # Multiprocessing
# pool = multiprocessing.Pool()
# toolbox.register("map", pool.map)
max_workers = 3
with concurrent.futures.ProcessPoolExecutor(max_workers=max_workers) as executor:
results = [executor.submit(main, ) for i in range(max_workers)]
for f in concurrent.futures.as_completed(results):
if f.result() != -1:
pop = f.result()
...and it works, but would be nice to know that the program's params would work the same?
Python 3.7, Windows 10.
Reproducible code is below. As you'll see, it IS encased in the
if __name__ == '__main__':
but still getting the error. If you put ALL the code under theif __name__ == '__main__':
you don't get the error, but then it doesn't seem to multiprocess? When you hit CTRL C to stop the program, it does shut down multiple processes, but when you look at your task manager/threads running, it's only running one at a time. Ideas?