summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2010-03-26 16:30:21 -0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2010-03-26 16:30:21 -0300
commit416a51459c911a3dd73aca4c10fd38d9f33afd42 (patch)
tree8eb77e7bae8d5d6e74efc03d5ab29179e8edddcc
parent2423432d3f03fe12e731118c2ba8a09e9ce0ee77 (diff)
downloadpython-linux-procfs-416a51459c911a3dd73aca4c10fd38d9f33afd42.tar.gz
pidstats: Catch more vanished processes cases
When the process vanishes after we got a list of pids that match some criteria, just catch it, remove it from the pid dictionary and continue. Reported-by: Clark Williams <williams@redhat.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rwxr-xr-xprocfs/procfs.py38
1 files changed, 31 insertions, 7 deletions
diff --git a/procfs/procfs.py b/procfs/procfs.py
index d8e6174..ab6cfa4 100755
--- a/procfs/procfs.py
+++ b/procfs/procfs.py
@@ -232,7 +232,7 @@ class pidstats:
if name == self.processes[pid]["stat"]["comm"]:
pids.append(pid)
except IOError:
- # We're doing late loading of /proc files
+ # We're doing lazy loading of /proc files
# So if we get this exception is because the
# process vanished, remove it
del self.processes[pid]
@@ -242,15 +242,27 @@ class pidstats:
def find_by_regex(self, regex):
pids = []
for pid in self.processes.keys():
- if regex.match(self.processes[pid]["stat"]["comm"]):
- pids.append(pid)
+ try:
+ if regex.match(self.processes[pid]["stat"]["comm"]):
+ pids.append(pid)
+ except IOError:
+ # We're doing lazy loading of /proc files
+ # So if we get this exception is because the
+ # process vanished, remove it
+ del self.processes[pid]
return pids
def find_by_cmdline_regex(self, regex):
pids = []
for pid in self.processes.keys():
- if regex.match(process_cmdline(self.processes[pid])):
- pids.append(pid)
+ try:
+ if regex.match(process_cmdline(self.processes[pid])):
+ pids.append(pid)
+ except IOError:
+ # We're doing lazy loading of /proc files
+ # So if we get this exception is because the
+ # process vanished, remove it
+ del self.processes[pid]
return pids
def get_per_cpu_rtprios(self, basename):
@@ -263,7 +275,13 @@ class pidstats:
if not pids or len([n for n in pids if n not in processed_pids]) == 0:
break
for pid in pids:
- priorities += "%s," % self.processes[pid]["stat"]["rt_priority"]
+ try:
+ priorities += "%s," % self.processes[pid]["stat"]["rt_priority"]
+ except IOError:
+ # We're doing lazy loading of /proc files
+ # So if we get this exception is because the
+ # process vanished, remove it
+ del self.processes[pid]
processed_pids += pids
cpu += 1
@@ -279,7 +297,13 @@ class pidstats:
if not pids or len([n for n in pids if n not in processed_pids]) == 0:
break
for pid in pids:
- priorities += "%s," % self.processes[pid]["stat"]["rt_priority"]
+ try:
+ priorities += "%s," % self.processes[pid]["stat"]["rt_priority"]
+ except IOError:
+ # We're doing lazy loading of /proc files
+ # So if we get this exception is because the
+ # process vanished, remove it
+ del self.processes[pid]
processed_pids += pids
cpu += 1