<DIV id=RTEContent>i have the following custom extenstion of Queue.Queue() to save and load</DIV> <DIV>queue contents but I think there's a problem with it.</DIV> <DIV>Does anybody know qhether Queue.Queue() is pickle-able? if so,</DIV> <DIV>can I get sample code? If not, can anybody recommend a pickle-able</DIV> <DIV>Queue from another library that I might be able to use?</DIV> <DIV>Thank you for any help!</DIV> <DIV> </DIV> <DIV>Here's my "PersistentQueue" extension:</DIV> <DIV> </DIV> <DIV>import cPickle<BR>import Queue<BR>import os<BR>from os.path import *</DIV> <DIV>class PersistentQueue(Queue.Queue):<BR> def __init__(self, maxsize=0):<BR> #print "init"<BR> Queue.Queue.__init__(self,maxsize)<BR> <BR> def saveState(self, file):<BR> fullFilePath = join(os.getcwd(),'savedStates', file)<BR>
#print fullFilePath<BR> f = open(fullFilePath, 'w')<BR> l = []<BR> while not self.empty():<BR> l.append(self.get())<BR> cPickle.dump(l, f)<BR> f.close()</DIV> <DIV> def loadState(self, file):<BR> fullFilePath = join(os.getcwd(),'savedStates', file)<BR> #print fullFilePath<BR> f = open(fullFilePath)<BR> l = cPickle.load(f)<BR> f.close()<BR> for i in l:<BR> self.put(i)</DIV> <DIV><BR>if __name__ == '__main__':<BR> q = PersistentQueue(20)<BR> q.loadState("q1.sav")<BR> print q.get()</DIV> <DIV>
q.put("four")<BR> q.saveState("q1.sav")</DIV><p>
<hr size=1> Yahoo! Mail<br>
<a href="http://us.rd.yahoo.com/mail_us/taglines/pmall2/*http://photomail.mail.yahoo.com">Use Photomail</a> to share photos without annoying attachments.