How to pickle a 'PySwigObject' ?

Barak, Ron Ron.Barak at lsi.com
Mon May 25 10:52:22 EDT 2009


Hi,

I have a wxPython application that is creating a subprocess that performs a lengthy log analysis.
Currently, the subprocess is displaying its results using its own MainLoop().
I want to display the subprocess' results using the parent process' MainLoop().

I tried to pickle the class instance that is displaying the subprocess results (so the subclass could be sent to the parent process for display), but I get the following error:

cPickle.PicklingError: Can't pickle <type 'PySwigObject'>: attribute lookup __builtin__.PySwigObject failed
A code that demonstrate the problem is:

$ cat pickle_test.py
#!/usr/bin/env python

#import pickle
import cPickle as pickle
import wx

class ListControl(wx.Frame):

    def __init__(self, parent, id):
        wx.Frame.__init__(self,parent,id)

if __name__ == "__main__":

    app = wx.App(redirect=False)
    output = pickle.dumps(ListControl(None, -1),2)

Any ideas what could be changed to let me pickle the class ?

Thanks,
Ron.

$ cat -n pickle_test.py
     1  #!/usr/bin/env python
     2
     3  #import pickle
     4  import cPickle as pickle
     5  import wx
     6
     7  class ListControl(wx.Frame):
     8
     9      def __init__(self, parent, id):
    10          wx.Frame.__init__(self,parent,id)
    11
    12  if __name__ == "__main__":
    13
    14      app = wx.App(redirect=False)
    15      output = pickle.dumps(ListControl(None, -1),2)

$ python -u pickle_test.py
Traceback (most recent call last):
  File "pickle_test.py", line 15, in <module>
    output = pickle.dumps(ListControl(None, -1),2)
cPickle.PicklingError: Can't pickle <type 'PySwigObject'>: attribute lookup __builtin__.PySwigObject failed

$
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090525/3bb4e813/attachment.html>


More information about the Python-list mailing list