i have the following custom extenstion of Queue.Queue() to save and load
queue contents but I think there's a problem with it.
Does anybody know qhether Queue.Queue() is pickle-able? if so,
can I get sample code? If not, can anybody recommend a pickle-able
Queue from another library that I might be able to use?
Thank you for any help!
 
Here's my "PersistentQueue" extension:
 
import cPickle
import Queue
import os
from os.path import *
class PersistentQueue(Queue.Queue):
   def __init__(self, maxsize=0):
      #print "init"
      Queue.Queue.__init__(self,maxsize)
     
   def saveState(self, file):
      fullFilePath = join(os.getcwd(),'savedStates', file)
    ! ;  #print fullFilePath
      f = open(fullFilePath, 'w')
      l = []
      while not self.empty():
         l.append(self.get())
      cPickle.dump(l, f)
      f.close()
   def loadState(self, file):
      fullFilePath = join(os.getcwd(),'savedStates', file)
      #print fullFilePath
      f = open(fullFilePath)
      l = cPickle.load(f)
      f.close()
      for i in l:
         self.put(i)

if __name__ == '__main__':
   q = PersistentQueue(20)
   q.loadState("q1.sav")
   print q.get()
   q.put("four")
   q.saveState("q1.sav")


Yahoo! Mail
Use Photomail to share photos without annoying attachments.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to