Created
January 11, 2020 14:55
-
-
Save narwanimonish/f8a95f929b7242dd4daa74a0e2afa5e5 to your computer and use it in GitHub Desktop.
Simulate CPU load on all cores
This file contains 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 | |
from multiprocessing import cpu_count | |
import signal | |
stop_loop = 0 | |
def exit_chld(x, y): | |
global stop_loop | |
stop_loop = 1 | |
def f(x): | |
global stop_loop | |
while not stop_loop: | |
x*x | |
signal.signal(signal.SIGINT, exit_chld) | |
if __name__ == '__main__': | |
processes = cpu_count() | |
print('-' * 20) | |
print('Running load on CPU(s)') | |
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