from multiprocessing import Process, Queue import sys import time ITEMS = 100 PAIN_LEVEL = 1000000 HAPINESS_LEVEL = 0 # 0 = Unhappy, 1 = Happy def producer(q): # Insert 100 items print("Inserting %d" % ITEMS) for i in range(ITEMS): q.put("ABCD" * PAIN_LEVEL) # Empty the queue print("Trying to get all items from the queue") c = 0 while not q.empty(): q.get() time.sleep(0.01 * HAPINESS_LEVEL) c += 1 print("Got %d items" % c) # Print the queue status print("Final queue status: length = %d, empty = %s" % (q.qsize(), q.empty())) # Actually flush the queue to be able to finish the process # NOT RELATED WITH THE DEMO while q.qsize()>0: q.get() if __name__ == '__main__': q = Queue() p = Process(target=producer, args=(q,)) p.start()