Don't save Curve._hooke when pickling or deepcopying.
authorW. Trevor King <wking@drexel.edu>
Mon, 16 Aug 2010 18:59:27 +0000 (14:59 -0400)
committerW. Trevor King <wking@drexel.edu>
Mon, 16 Aug 2010 18:59:27 +0000 (14:59 -0400)
Two reasons:
1) It crashes because hooke.config._comment_textwrap contains a
   compiled regexp, and these cannot be deepcopied.  See
     http://mail.python.org/pipermail/python-dev/2008-November/083348.html
     http://bugs.python.org/issue416670
2) We don't want to copy Hooke instances anyway, since we need them to stay
   in sync.  Anything copying curves (e.g. Playlist.filter) should shallow
   copy Hooke instances between the curves.
If this turns up anywhere else, we should think about adding a
Curve.copy method to get the "just right" copy depth ;).

hooke/curve.py

index ed76c8a557d08566d6495c2a7e86854f473970cc..a87a7fd52b776d72d397cf2ed13f48461673d173 100644 (file)
@@ -41,6 +41,7 @@ class NotRecognized (ValueError):
             super(NotRecognized, self).__init__(msg)
             self.curve = data
 
+
 class Data (numpy.ndarray):
     """Stores a single, continuous data set.
 
@@ -183,6 +184,16 @@ class Curve (object):
     def __repr__(self):
         return self.__str__()
 
+    def __getstate__(self):
+        data = dict(self.__dict__)
+        del(data['_hooke'])
+        return data
+
+    def __setstate__(self, data):
+        self._hooke = None
+        for key,value in data.items():
+            setattr(self, key, value)
+
     def set_hooke(self, hooke=None):
         if hooke != None:
             self._hooke = hooke