Queue

A queue is process shared queue implementation. It is used as a way to pass information among the processes.

from multiprocessing import Queue
from threading import Thread
 
q = Queue()
 
def worker():
    while True:
        value = q.get()
        print(f"Got some value {value}")
 
t = Thread(target=worker)
 
t.start()
 
 
q.put(1)
"Got some value 1"
 
q.put("something")
"Got some value something"

q.get method blocks until it gets a value. It accepts arguments block and timeout. block is by default True and timeout is None. Passing a timeout will throw an empty queue exception if queue doesn’t get a value by the time.