模拟CPU使用接近100%,如果是多核CPU,将下面脚本同时运行多个就可以。
1
2
3
4
def deadloop():
while True:
pass
deadloop()
调用子进程
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import subprocess
def run_cmd(cmd):
try:
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result_f,error_f = process.stdout,process.stderr
errors = error_f.read()
if errors:
raise Exception(errors)
else:
result = result_f.read().decode()
return result
except Exception as e:
print('Exception: ' + str(e))