Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from multiprocessing.pool import ThreadPool
- from multiprocessing import Pool
- import concurrent.futures
- import sys
- import time
- def testFunc(idx):
- x = 0
- # Some Math
- for i in range(100000000):
- x += idx + i
- x /= 1.5
- return x
- def run():
- # My Machine has 10 Cores and 20 Logical Processors. I set 15 Processes
- # pool = ThreadPool(processes=15) # Per 1 thread
- pool = Pool(processes=15) # Per all threads
- def callbackFunc(args):
- print('Result: ' + str(args))
- for i in range(50):
- pool.apply_async(testFunc, args=(i,), callback=callbackFunc)
- pool.close()
- pool.join()
- if __name__ == '__main__':
- start = time.time()
- run()
- end = time.time()
- print('Time: ' + str(end - start))
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement