I have an object with a CookieJar that I want to pickle.
However as you all probably know, pickle chokes on objects that contain lock objects. And for some horrible reason, a CookieJar has a lock object.
from cPickle import dumps
from cookielib import CookieJar
class Person(object):
def __init__(self, name):
self.name = name
self.cookies = CookieJar()
bob = Person("bob")
dumps(bob)
# Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# cPickle.UnpickleableError: Cannot pickle <type 'thread.lock'> objects
How do I persist this?
The only solution I can think of is to use FileCookieJar.save and FileCookieJar.load to a stringIO object. But is there a better way?