It took me a while to figure out what you want. The problem is how multiprocessing works. Basically, you need to write your program in a functional style, instead of relying on the side effects as it is now.
Right now, you are sending objects to your pool that you need to change, and do not return anything from countSixes . This will not work with multiprocessing, because in order to get around the GIL , multiprocessing creates a copy of counter and sends it to a completely new translator. Therefore, when you increase i , you actually increase the copy of i , and then because you are not returning anything, you are dropping it!
To do something useful, you need to return something from countSixes . Here is a simplified version of your code that does something similar to what you want. I left the argument, just to show what you should do, but actually it can be done using the zero-arg function.
import random def countSixes(start): newNum = random.randrange(0,10) if newNum == 6: return start + 1 else: return start if __name__ == '__main__': import multiprocessing pool = multiprocessing.Pool(1)
source share