[FIXED] Multiprocessing with two functions while sharing data

Issue

I'm new with multiprocessing in Python. I need three functions to run simultaneously while also doing stuff to the same "multiprocessing queues" and exchanging information. My main problem is that when I make any changes to the contents of this queues in any of these functions, the other functions doesn't realize them in real time.

def func1(queueFrames):
    a = 0
    while 1 :
        queueFrames.put(a)
        a =+1



def func2(queueFrames):
    while 1:
        print(queueFrames.get())



if __name__ == '__main__':
    queueFrames = mp.Queue()
    queueAirgun = mp.Queue()
    p1 = mp.Process(target=func1,args=(queueFrames,))
    p1.start()
    p2 = mp.Process(target=func2, args=(queueFrames,))
    p2.start()

I'm getting this output.

enter image description here

But I want output to be 1 2 3 4 5 6.... I don't know if it is a synchronization issue. Thanks for help!


Solution

Replace a =+ 1 is incorrect. Python only recognizes +=.



Answered By - error_man
Answer Checked By - Cary Denson (Python.Easybugfix Admin)

Related Posts

Post a Comment