The while
loop you have in your code is wrong because you don't want the function_to_get_from_q()
process to quit everytime it checks the queue and it's empty. In the code below, a special value is put()
into the queue to indicate that it's the last one.
import multiprocessing as mpimport datetime as dtSENTINEL = 'stop'def function_to_get_from_q(queue): while (value := queue.get()) != SENTINEL: print(value)def collect(queue): for i in range(10000): t = dt.datetime.utcnow() + dt.timedelta(hours=5, minutes=30) queue.put([i, t.strftime('%H:%M:%S')]) queue.put(SENTINEL) # Indicate end.if __name__ == "__main__": queue = mp.Queue() process1 = mp.Process(target=collect, args=(queue,)) process2 = mp.Process(target=function_to_get_from_q, args=(queue,)) process1.start() process2.start() print('fini')