import math
import multiprocessing as m
import time

threadCount = 8
maxNum = 10 ** 7

startTime = time.time()
total = 0

result_list = []
def log_results(result):
    result_list.append(result)

def calculate(start, end):
    temp = 0
    for d in range(start, end):
        temp = temp + (1/d) ** 2
    return temp

if __name__ == '__main__':
    pool = m.Pool()
    for threads in range(0, threadCount):
        pool.apply_async(calculate, args = (round(maxNum/threadCount*threads)+1, round(maxNum/threadCount*(threads+1)),), callback = log_results)
    pool.close()
    pool.join()

    total = sum(result_list)

    print("\nFinished in " + str(round(time.time() - startTime)) + " seconds")
    print("Pi: " + str(math.sqrt(total * 6)))