Browse Source

capture_output was only introduced in python 3.7

pull/11/head
Egon Rijpkema 3 years ago
parent
commit
87e2e49b92
  1. 8
      roles/kill_memory_hogs/files/kill_hoggs.py

8
roles/kill_memory_hogs/files/kill_hoggs.py

@ -52,7 +52,8 @@ def find_terminals_of_user(user: str): @@ -52,7 +52,8 @@ def find_terminals_of_user(user: str):
Returns:
list: A list of terminals (string)
"""
terminals = subprocess.run('w -s -h', shell=True, capture_output=True)
terminals = subprocess.run(
'w -s -h', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return [
t.split()[1]
for t in str(terminals.stdout).strip('b\'').strip('').split('\\n')
@ -139,9 +140,8 @@ def kill_hogs(memory_threshold, @@ -139,9 +140,8 @@ def kill_hogs(memory_threshold,
if data['memory_percent'] > memory_threshold or data['cpu_percent'] > cpu_threshold:
message = [
'User {} uses \n {:.2f} % of cpu. '.format(
username,
data['cpu_percent']), '{:.2f} % of memory. '.format(
data['memory_percent']),
username, data['cpu_percent']),
'{:.2f} % of memory. '.format(data['memory_percent']),
'The following processes will be killed:'
]
for proc in data['processes']:

Loading…
Cancel
Save