Fix 'NoSuchProcess' exception in process_checker (#5716)
The psutil library used in process_checker create a cache for each process when calling process_iter. So, there is some possibility that one process exists when calling process_iter, but not exists when calling cmdline, which will raise a NoSuchProcess exception. This commit fix the issue. Signed-off-by: bingwang <bingwang@microsoft.com>
This commit is contained in:
parent
9e34003136
commit
36c52cca2b
@ -28,9 +28,12 @@ def check_process_existence(container_name, process_cmdline):
|
|||||||
# state, then it will be marked as 'running'.
|
# state, then it will be marked as 'running'.
|
||||||
is_running = False
|
is_running = False
|
||||||
for process in psutil.process_iter(["cmdline", "status"]):
|
for process in psutil.process_iter(["cmdline", "status"]):
|
||||||
if ((' '.join(process.cmdline())).startswith(process_cmdline) and process.status() in ["running", "sleeping"]):
|
try:
|
||||||
is_running = True
|
if ((' '.join(process.cmdline())).startswith(process_cmdline) and process.status() in ["running", "sleeping"]):
|
||||||
break
|
is_running = True
|
||||||
|
break
|
||||||
|
except psutil.NoSuchProcess:
|
||||||
|
pass
|
||||||
|
|
||||||
if not is_running:
|
if not is_running:
|
||||||
# If this script is run by Monit, then the following output will be appended to
|
# If this script is run by Monit, then the following output will be appended to
|
||||||
|
Reference in New Issue
Block a user