Skip to content

Instantly share code, notes, and snippets.

@DamianZaremba
Created June 9, 2011 15:37
Show Gist options
  • Save DamianZaremba/1016999 to your computer and use it in GitHub Desktop.
Save DamianZaremba/1016999 to your computer and use it in GitHub Desktop.
#!/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