class ComplexType: def __init__(self, shared=None): if shared is not None: self.shared = shared else: self.shared = Value(ComplexData) self.worker = Fib() def calc(self, number): self.shared.fib = self.worker.calc(number) def result(self): return self.shared.fib
## does not spawn inner threads with ThreadPoolExecutor(max_workers=procnum) as executor: executor.map(processWorker, calcList) # ## spawns 3 inner threads # with MultiprocessingThreadPool( processes=procnum ) as pool: # pool.map( processWorker, calcList ) # # ## spawns 3 inner threads # with MultiprocessingProcessPool( processes=procnum ) as pool: # pool.map( processWorker, calcList ) procEndTime = time.time() fib = Fib() fib.calc(fib_arg) refEndTime = time.time() procDur = procEndTime - procStartTime refDur = refEndTime - procEndTime results = [] for calcPar in calcList: fib = calcPar[0] val = fib.result() results.append(val) print("Results:", results) print("Reference duration:", refDur, "sec") print("Processes duration:", procDur, "sec", (procDur / refDur * 100), "%")