Skip to content

Instantly share code, notes, and snippets.

@cdgraff
Created December 28, 2018 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdgraff/52e414fb3254910b47e9cdc8bc0d5f78 to your computer and use it in GitHub Desktop.
Save cdgraff/52e414fb3254910b47e9cdc8bc0d5f78 to your computer and use it in GitHub Desktop.
cpuload.py
#!/usr/bin/env python
"""
Produces load on all available CPU cores
"""
from multiprocessing import Pool
from multiprocessing import cpu_count
def f(x):
while True:
x*x
if __name__ == '__main__':
processes = cpu_count()
print '-' * 20
print 'Running load on CPU'
print 'Utilizing %d cores' % processes
print '-' * 20
pool = Pool(processes)
pool.map(f, range(processes))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment