Python Threading Example Queue

Use python threads and queues together to execute code in parallel (python multithreading, concurrency, and parallelism).

import Queue
import threading
class Worker(threading.Thread):
    def __init__(self, queue):
        self.queue = queue
    def run(self):
        while True:
            task = self.queue.get()
queue = Queue.Queue()
for i in range(NUMBER_OF_THREADS):
    t = Worker(queue)
    t.daemon = True
for obj in MyModel.objects.all():
Did this help you? Please let me know with a comment. Thank you
Posted .

Comments (RSS)

Leave a comment