All, While trying to write game state, I found that objects containing pyglet sprites, etc would not pickle due to embedded ctypes. For example:
>>> import pyglet >>> image = pyglet.resource.image('star.png') >>> import pickle >>> pickle.dumps(image) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/ lib/python2.7/pickle.py", line 1374, in dumps Pickler(file, protocol).dump(obj) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/ lib/python2.7/pickle.py", line 224, in dump self.save(obj) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/ lib/python2.7/pickle.py", line 331, in save self.save_reduce(obj=obj, *rv) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/ lib/python2.7/pickle.py", line 419, in save_reduce save(state) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/ lib/python2.7/pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/ lib/python2.7/pickle.py", line 649, in save_dict self._batch_setitems(obj.iteritems()) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/ lib/python2.7/pickle.py", line 663, in _batch_setitems save(v) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/ lib/python2.7/pickle.py", line 331, in save self.save_reduce(obj=obj, *rv) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/ lib/python2.7/pickle.py", line 419, in save_reduce save(state) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/ lib/python2.7/pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/ lib/python2.7/pickle.py", line 649, in save_dict self._batch_setitems(obj.iteritems()) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/ lib/python2.7/pickle.py", line 663, in _batch_setitems save(v) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/ lib/python2.7/pickle.py", line 306, in save rv = reduce(self.proto) ValueError: ctypes objects containing pointers cannot be pickled I have worked around this by manually excluding/reconstituting pyglet images and sprites from my objects using __getstate__ and __setstate__. The downside for me is the extra work/code that is required. Are there any plans to make pyglet objects amenable to pickling? -- You received this message because you are subscribed to the Google Groups "pyglet-users" group. To post to this group, send email to pyglet-users@googlegroups.com. To unsubscribe from this group, send email to pyglet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en.