From 6ec352fe926b3335e6ae3c5e6b28bfb6d334d325 Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@allmydata.com>
Date: Fri, 5 Dec 2008 15:54:12 -0700
Subject: [PATCH] misc/cpu-watcher.tac: tolerate disk-full errors when writing
 the pickle, and pickle corruption from earlier disk-full errors

---
 misc/cpu-watcher.tac | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/misc/cpu-watcher.tac b/misc/cpu-watcher.tac
index 9695a694..12f29324 100644
--- a/misc/cpu-watcher.tac
+++ b/misc/cpu-watcher.tac
@@ -104,7 +104,7 @@ class CPUWatcher(service.MultiService, resource.Resource, Referenceable):
         resource.Resource.__init__(self)
         try:
             self.history = pickle.load(open("history.pickle", "rb"))
-        except EnvironmentError:
+        except:
             self.history = {}
         self.current = []
         self.observers = set()
@@ -199,8 +199,11 @@ class CPUWatcher(service.MultiService, resource.Resource, Referenceable):
             except:
                 log.msg("error reading process %s (%s), ignoring" % (pid, name))
                 log.err()
-        pickle.dump(self.history, open("history.pickle.tmp", "wb"))
-        os.rename("history.pickle.tmp", "history.pickle")
+        try:
+            pickle.dump(self.history, open("history.pickle.tmp", "wb"))
+            os.rename("history.pickle.tmp", "history.pickle")
+        except:
+            pass
         for (pid, name) in processes:
             row = [name]
             for avg in self.AVERAGES:
-- 
2.45.2