Catch FileNotFoundError when listing namespace PIDs

During the namespace PID listing, if a process is stopped, it will
disappear from "/proc/<pid>". When "os.stat(path)" is executed on
an unexistent path, returns "FileNotFoundError". This exception
should be catched and ignored.

Change-Id: Icde5e15bd97578f5ec8273f22ef8384502be1850
Related-Bug: #1841753
This commit is contained in:
Rodolfo Alonso Hernandez 2019-10-31 15:32:09 +00:00
parent cc3886fd78
commit 9ad03dcf96

View File

@ -216,7 +216,7 @@ def list_ns_pids(namespace):
try:
ns_path = os.path.join(NETNS_RUN_DIR, namespace)
ns_inode = os.stat(ns_path).st_ino
except OSError:
except (OSError, FileNotFoundError):
return ns_pids
for pid in os.listdir('/proc'):
@ -226,7 +226,7 @@ def list_ns_pids(namespace):
pid_path = os.path.join('/proc', pid, 'ns', 'net')
if os.stat(pid_path).st_ino == ns_inode:
ns_pids.append(int(pid))
except OSError:
except (OSError, FileNotFoundError):
continue
return ns_pids