0

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?

3
  • 2
    1000!=8.2639316883×10^(5,565,708) There is nothing simple about it. Commented Jan 11, 2013 at 17:00
  • Of course not, but the code is simple. Commented Jan 11, 2013 at 17:01
  • What I mean by that is that the code for doing factorials without multiprocessing is relatively simple code. Commented Jan 11, 2013 at 17:13

1 Answer 1

1

The program works fine --- until the print final. Then it spends a very large amount of time trying to print this number, which is seriously huge...

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, it finished computing after about 15 minutes when I let it run, following your comment.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.