I am trying to figure out how to use the concurrent.futures module in Python 3.2.2, and have played with examples from the documentation. When I try to apply my understanding, my own examples fail. I hope someone can help me hit the road!
I want to be able to install multiple processes simultaneously, but asynchronously. My processes do not return anything. To simulate this, I wrote a trivial example:
import concurrent.futures fred = [1,2,3,4,5,6,7,8,9,10] def f(x): print(x * x) def main(): with concurrent.futures.ProcessPoolExecutor() as executor: for num in fred: executor.submit(f, num) if __name__ == "__main__": main()
This code is launched (in the quad-core window of Windows XP) and returns:
1 4 9 16 25
... but then freezes.
Itโs clear that I am doing something wrong. So what is the right way to start Python processes in a process pool? I do not want to use the executor.map approach because I have no return from my process.
Or ... do I need to fake it by returning a True or False process (or something)?
Thanks!
Mappagnosis
source share