Created
November 9, 2012 18:05
-
-
Save psobot/4047223 to your computer and use it in GitHub Desktop.
Buffered Read Queue for Multiprocessing in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Queue | |
import multiprocessing | |
import threading | |
class BufferedReadQueue(Queue.Queue): | |
def __init__(self, lim=None): | |
self.raw = multiprocessing.Queue(lim) | |
self.__listener = threading.Thread(target=self.listen) | |
self.__listener.setDaemon(True) | |
self.__listener.start() | |
Queue.Queue.__init__(self, lim) | |
def listen(self): | |
try: | |
while True: | |
self.put(self.raw.get()) | |
except: | |
pass | |
@property | |
def buffered(self): | |
return self.qsize() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment