I am starting to learn multiprocessing in python, but have arrived to a point where my code just hangs. It is simply computing 1 000 000 factorial, using multithreading.
import multiprocessing def part(n): ret = 1 n_max = n + 9999 while n <= n_max: ret *= n n += 1 print "Part "+ str(n-1) + " complete" return ret def buildlist(n_max): n = 1 L = [] while n <= n_max: L.append(n) n += 10000 return L final = 1 ne = 0 if __name__ == '__main__': pool = multiprocessing.Pool() results = [pool.apply_async(part, (x,)) for x in buildlist(1000000)] for r in results: x = r.get() final *= x ne+= 1 print ne print final I have included some print functions to try to diagnose where the code hangs, and it will print the string included in the part function 100 times, as expected. The "print ne" also works 100 times.
The problem is that final won't print, and the code doesn't complete.
How do I fix this problem?
Edit: Also, since this is being downvoted, could someone explain what I am doing wrong/why I am being downvoted?
1000!=8.2639316883×10^(5,565,708)There is nothing simple about it.