【发布时间】:2013-05-25 21:34:11
【问题描述】:
我有一个使用队列对象列表的类。我需要腌制这个类,包括保存在队列对象中的信息。例如:
import Queue
import pickle
class QueueTest(object):
def __init__(self):
self.queueList = []
def addQueue(self):
q = Queue.Queue()
q.put('test')
self.queueList.append(q)
obj = QueueTest()
obj.addQueue()
with open('pickelTest.dat','w') as outf:
pickle.dump(obj,outf)
返回错误
raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle lock objects
有没有办法腌制 Queue 对象?
【问题讨论】:
-
你需要
Queue.Queue的同步功能吗?也就是说,您是使用队列在各个线程之间进行通信,还是仅仅作为常规数据结构? -
只是一个普通的数据结构
标签: python python-2.7 pickle