Skip to content

Instantly share code, notes, and snippets.

@tott
Created October 15, 2012 21:57
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 21 You must be signed in to fork a gist
  • Save tott/3895832 to your computer and use it in GitHub Desktop.
Save tott/3895832 to your computer and use it in GitHub Desktop.
create cpu load in python
#!/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 'utilizing %d cores\n' % processes
pool = Pool(processes)
pool.map(f, range(processes))
@solarisfire
Copy link

Won't exit on ctrl-c?

@klahnen
Copy link

klahnen commented Jun 3, 2016

Try ctr+z

@jayboro100
Copy link

Those who are in newer version of python, don't forget to put parenthesis in: print 'utilizing %d cores\n' % processes .. so as look like: print ('utilizing %d cores\n' % processes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment