Created
June 9, 2011 15:37
-
-
Save DamianZaremba/1016999 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/python | |
import threading | |
import Queue | |
class Runner(threading.Thread): | |
def __init__(self, queue): | |
threading.Thread.__init__(self) | |
self.queue = queue | |
def run(self): | |
while True: | |
job = self.queue.get() | |
# do shit | |
self.queue.task_done() | |
if __name__ == "__main__": | |
queue = Queue.Queue() | |
for i in range(10): | |
thread = Runner(queue) | |
thread.setDaemon(True) | |
thread.start() | |
# Do this lots of times in one thread | |
queue.put({}) | |
# DO this on exit - stops all the threads | |
queue.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment