python-linux-procfs: Propagate error to user if a pid is completed

If a pid is completed and disappears a FileNotFoundError will occur
because /proc/pid/stat will disappear too.

It is not possible to check for the file first because it could still
disappear between the time of the check and the time of use.

Propagate this error to the user.
The user should handle this with a try, except clause and ignore it if
an exception occurs.

Reviewed-by: Leah Leshchinsky <lleshchi@redhat.com>
Signed-off-by: John Kacur <jkacur@redhat.com>
diff --git a/procfs/procfs.py b/procfs/procfs.py
index 408b2bc..a0e9977 100755
--- a/procfs/procfs.py
+++ b/procfs/procfs.py
@@ -130,7 +130,12 @@
 
     def __init__(self, pid, basedir="/proc"):
         self.pid = pid
-        self.load(basedir)
+        try:
+            self.load(basedir)
+        except FileNotFoundError:
+            # The file representing the pid has disappeared
+            #  propagate the error to the user to handle
+            raise
 
     def __getitem__(self, fieldname):
         return self.fields[fieldname]
@@ -151,7 +156,11 @@
         return fieldname in self.fields
 
     def load(self, basedir="/proc"):
-        f = open("%s/%d/stat" % (basedir, self.pid))
+        try:
+            f = open("%s/%d/stat" % (basedir, self.pid))
+        except FileNotFoundError:
+            # The pid has disappeared, propagate the error
+            raise
         fields = f.readline().strip().split(') ')
         f.close()
         fields = fields[0].split(' (') + fields[1].split()
@@ -338,7 +347,11 @@
                 else:
                     sclass = pidstatus
 
-                setattr(self, attr, sclass(self.pid, self.basedir))
+                try:
+                    setattr(self, attr, sclass(self.pid, self.basedir))
+                except FileNotFoundError:
+                    # The pid has disappeared, progate the error
+                    raise
             elif attr == "cmdline":
                 self.load_cmdline()
             elif attr == "threads":