Last active
September 13, 2017 08:19
-
-
Save ultimate010/f1bf1b761cdf7ada872c73d6e3b0d418 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from multiprocessing import Pool | |
| import multiprocessing | |
| from time import sleep | |
| def f(x): | |
| # Put any cpu (only) consuming operation here. I have given 1 below - | |
| count = 0 | |
| some_str = ' ' * 512000000 * 3 | |
| while True: | |
| count += 1 | |
| if count % 10000000 == 0: | |
| count = 1 | |
| sleep(1) | |
| x * x | |
| # decide how many cpus you need to load with. | |
| no_of_cpu_to_be_consumed = multiprocessing.cpu_count() | |
| p = Pool(processes=no_of_cpu_to_be_consumed) | |
| p.map(f, range(no_of_cpu_to_be_consumed)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment