Skip to content

Instantly share code, notes, and snippets.

@ultimate010
Last active September 13, 2017 08:19
Show Gist options
  • Save ultimate010/f1bf1b761cdf7ada872c73d6e3b0d418 to your computer and use it in GitHub Desktop.
Save ultimate010/f1bf1b761cdf7ada872c73d6e3b0d418 to your computer and use it in GitHub Desktop.
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