mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Merge pull request #23055 from jfindlay/fix_ps
prevent ps module errors on accessing dead procs
This commit is contained in:
commit
c2416a425f
@ -46,7 +46,10 @@ def _get_proc_cmdline(proc):
|
|||||||
|
|
||||||
It's backward compatible with < 2.0 versions of psutil.
|
It's backward compatible with < 2.0 versions of psutil.
|
||||||
'''
|
'''
|
||||||
|
try:
|
||||||
return proc.cmdline() if PSUTIL2 else proc.cmdline
|
return proc.cmdline() if PSUTIL2 else proc.cmdline
|
||||||
|
except (psutil.NoSuchProcess, psutil.AccessDenied):
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
def _get_proc_create_time(proc):
|
def _get_proc_create_time(proc):
|
||||||
@ -55,7 +58,10 @@ def _get_proc_create_time(proc):
|
|||||||
|
|
||||||
It's backward compatible with < 2.0 versions of psutil.
|
It's backward compatible with < 2.0 versions of psutil.
|
||||||
'''
|
'''
|
||||||
|
try:
|
||||||
return proc.create_time() if PSUTIL2 else proc.create_time
|
return proc.create_time() if PSUTIL2 else proc.create_time
|
||||||
|
except (psutil.NoSuchProcess, psutil.AccessDenied):
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _get_proc_name(proc):
|
def _get_proc_name(proc):
|
||||||
@ -64,12 +70,10 @@ def _get_proc_name(proc):
|
|||||||
|
|
||||||
It's backward compatible with < 2.0 versions of psutil.
|
It's backward compatible with < 2.0 versions of psutil.
|
||||||
'''
|
'''
|
||||||
ret = []
|
|
||||||
try:
|
try:
|
||||||
ret = proc.name() if PSUTIL2 else proc.name
|
return proc.name() if PSUTIL2 else proc.name
|
||||||
except (psutil.NoSuchProcess, psutil.AccessDenied):
|
except (psutil.NoSuchProcess, psutil.AccessDenied):
|
||||||
pass
|
return []
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
def _get_proc_status(proc):
|
def _get_proc_status(proc):
|
||||||
@ -78,7 +82,10 @@ def _get_proc_status(proc):
|
|||||||
|
|
||||||
It's backward compatible with < 2.0 versions of psutil.
|
It's backward compatible with < 2.0 versions of psutil.
|
||||||
'''
|
'''
|
||||||
|
try:
|
||||||
return proc.status() if PSUTIL2 else proc.status
|
return proc.status() if PSUTIL2 else proc.status
|
||||||
|
except (psutil.NoSuchProcess, psutil.AccessDenied):
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _get_proc_username(proc):
|
def _get_proc_username(proc):
|
||||||
@ -87,7 +94,10 @@ def _get_proc_username(proc):
|
|||||||
|
|
||||||
It's backward compatible with < 2.0 versions of psutil.
|
It's backward compatible with < 2.0 versions of psutil.
|
||||||
'''
|
'''
|
||||||
|
try:
|
||||||
return proc.username() if PSUTIL2 else proc.username
|
return proc.username() if PSUTIL2 else proc.username
|
||||||
|
except (psutil.NoSuchProcess, psutil.AccessDenied):
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _get_proc_pid(proc):
|
def _get_proc_pid(proc):
|
||||||
@ -137,7 +147,7 @@ def top(num_processes=5, interval=3):
|
|||||||
if num_processes and idx >= num_processes:
|
if num_processes and idx >= num_processes:
|
||||||
break
|
break
|
||||||
if len(_get_proc_cmdline(process)) == 0:
|
if len(_get_proc_cmdline(process)) == 0:
|
||||||
cmdline = [_get_proc_name(process)]
|
cmdline = _get_proc_name(process)
|
||||||
else:
|
else:
|
||||||
cmdline = _get_proc_cmdline(process)
|
cmdline = _get_proc_cmdline(process)
|
||||||
info = {'cmd': cmdline,
|
info = {'cmd': cmdline,
|
||||||
|
Loading…
Reference in New Issue
Block a user