-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstress.py
31 lines (28 loc) · 857 Bytes
/
stress.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
## FIXED ARGS
#def stress():
# import subprocess
# response = ""
# response += "<br/> \n"
# response += str(subprocess.Popen('stress -c 10 -t 1', shell=True, stdout=subprocess.PIPE).stdout.read().decode("utf-8"))
# response += "<br/> \n"
# return response
def stress(**kwargs):
import subprocess
cmd = '/usr/bin/stress '
for key, value in kwargs.items():
cmd += ( "--%s %s " %( key, value ) )
response = ""
response += "cmd: " + cmd + " <br/> \n"
try:
cmd_output = subprocess.check_output(
cmd,
stderr=subprocess.STDOUT,
shell=True,
universal_newlines=True
)
except subprocess.CalledProcessError as exc:
response += "ERROR: " + str(exc.returncode) + " <br/> \n" + str(exc.output) + " <br/> \n"
else:
response += str(cmd_output) + " <br/> \n"
response += "<br/> \n"
return response