Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. import multiprocessing
  2.  
  3. class ItemExists(Exception):
  4.     pass
  5.  
  6. class SetQueue(multiprocessing.JoinableQueue):
  7.  
  8.     def __init__(self, maxsize=0):
  9.         super(SetQueue,self).__init__(maxsize)
  10.         self.all_items = set()
  11.  
  12.     def put(self, obj, block=True,timeout=None):
  13.         if obj not in self.all_items:
  14.             super(SetQueue,self).put(obj,block,timeout)
  15.             self.all_items.add(item)
  16.         else:
  17.             raise ItemExists
  18.  
  19.     def get(self, block = True, timeout = None):
  20.         res = super(SetQueue,self).get( block, timeout)
  21.         self.all_items.discard(res)
  22.         return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement