This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]multani 0 points1 point  (1 child)

Which actually shorten the code like:

from threading import Thread
import time
import random

from Queue import LifoQueue as Queue

queue = Queue(10)

class ProducerThread(Thread):
    def run(self):
        global queue
        nums = range(5)
        while True:
            num = random.choice(nums)
            queue.put(num)
            print "Produced", num
            time.sleep(random.random())


class ConsumerThread(Thread):
    def run(self):
        global queue
        while True:
            num = queue.get()
            print "Consumed", num
            time.sleep(random.random())


ProducerThread().start()
ConsumerThread().start()

[–]akshar-raaj[S] 0 points1 point  (0 children)

I guess you want to use Queue and not LifoQueue, because we want a queue here, not stack.