Deal with deleted users before logind restart
This commit is contained in:
parent
007b0efb5d
commit
1071f4b66e
23
lsusers.py
23
lsusers.py
|
@ -36,16 +36,19 @@ def get_users_list():
|
||||||
|
|
||||||
|
|
||||||
def get_resources_percent(username=None):
|
def get_resources_percent(username=None):
|
||||||
if username is None:
|
try:
|
||||||
user_opt = ['-e']
|
if username is None:
|
||||||
else:
|
user_opt = ['-e']
|
||||||
user_opt = ['-u', username]
|
else:
|
||||||
cmd = Popen(['ps', '-o', 'pcpu', '--no-headers'] + user_opt, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
|
user_opt = ['-u', username]
|
||||||
output = list(map(float, cmd.stdout.read().decode('utf8').split()))
|
cmd = Popen(['ps', '-o', 'pcpu', '--no-headers'] + user_opt, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
|
||||||
cpu_percent = sum(output) / NCPUS
|
output = list(map(float, cmd.stdout.read().decode('utf8').split()))
|
||||||
cmd = Popen(['ps', '-o', 'pmem', '--no-headers'] + user_opt, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
|
cpu_percent = sum(output) / NCPUS
|
||||||
output = map(float, cmd.stdout.read().decode('utf8').split())
|
cmd = Popen(['ps', '-o', 'pmem', '--no-headers'] + user_opt, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
|
||||||
mem_percent = sum(output)
|
output = map(float, cmd.stdout.read().decode('utf8').split())
|
||||||
|
mem_percent = sum(output)
|
||||||
|
except:
|
||||||
|
cpu_percent = mem_percent = 0
|
||||||
return cpu_percent, mem_percent
|
return cpu_percent, mem_percent
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue