python multiprocessing does not run at same time -


i trying make python program runs multiple processes each in infinite loop @ same time, 1 process execute @ time, first 1 in code, rest of program not run. need make both procceses , main 1 execute @ same time?

from multiprocessing import * import time   def test1(q):     while true:         q.put("banana")         time.sleep(2)    def test2(q):     while true:         q.put("internet")         time.sleep(3)   if __name__ == "__main__":      q = queue()      t1 = process(target=test1(q))      t2 = process(target=test2(q))      t1.start()      t2.start()      q.put("rice")      while true:          print(q.get()) 

the reason problem lines:

     t1 = process(target=test1(q)      t2 = process(target=test2(q) 

there call test1 , test2, respectively (even though never reach test2 call. after running functions use return result target. want is:

     t1 = process(target=test1, args=(q,))      t2 = process(target=test2, args=(q,)) 

thus, not want run test1 , test2functions, use references (addresses) target , have provide there input arguments in separate parameter args.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -