How to compute Pi using multiprocessing module?
I'd like to make this function use multiprocessing for the first 3 steps in the while loop, which are independent of each other. I can't see how to do that without creating functions. I don't know how to do it with functions either since I don't think local variables can be modified externally. The code is from the Python documentation for the decimal module. def pi(): """Compute Pi to the current precision.""" getcontext().prec += 2 # extra digits for intermediate steps three = Decimal(3) # substitute "three=3.0" for regular floats lasts, t, s, n, na, d, da = 0, three, 3, 1, 0, 0, 24 while s != lasts: lasts = s n, na = n+na, na+8 d, da = d+da, da+32 t = (t * n) / d s += t getcontext().prec -= 2 return +s # unary plus applies the new precision