artemp/trac2github — Issue #168: Map pickling failure due to mapnik.Color object
Author: artemp
Created: 2011-10-09 20:17:43+00:00
State: open
Labels: Boost_Python_Binding

It appears that the Color class is not properly pickle-able, despite having a `color_pickle_suite` defined in source:trunk/bindings/python/mapnik_color.cpp#L32

{{{
>>> import pickle
>>> import mapnik
>>> output = open('map.pkl', 'wb')
>>> m = mapnik.Map(45,45)
>>> m.background = mapnik.Color(0,0,0)
>>> pickle.dump(m, output)
Traceback (most recent call last):
File "", line 1, in
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", line 1362, in dump
Pickler(file, protocol).dump(obj)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", line 224, in dump
self.save(obj)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", line 419, in save_reduce
save(state)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", line 562, in save_tuple
save(element)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", line 400, in save_reduce
save(func)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", line 295, in save
self.save_global(obj)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", line 753, in save_global
(obj, module, name))
pickle.PicklingError: Can't pickle : it's not the same object as mapnik._mapnik.Color
}}}

also, without explicitly setting a background color, error upon loading the pickled map:

{{{
>>> import pickle
>>> import mapnik
>>> output = open('map.pkl', 'wb')
>>> m = mapnik.Map(45,45)
>>> pickle.dump(m, output)
>>> output.close()
>>> reader = pickle.load(open('map.pkl', 'rb'))
Traceback (most recent call last):
File "", line 1, in
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", line 1370, in load
return Unpickler(file).load()
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", line 858, in load
dispatch[key](self)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pickle.py", line 1217, in load_build
setstate(state)
TypeError: No registered converter was able to produce a C++ rvalue of type mapnik::Color from this Python object of type NoneType
}}}