topic description
wants to write two child processes in python. Child process 1 continuously generates data (a list) and passes it to child process 2 for data processing every 5 seconds. I used multiprocessing.Manager (). List () to create a shared list as a shared variable for the two child processes. But it seems that process 2 does not capture the shared variable and prompts
TheFileNotFoundError: [WinError 2] system cannot find the specified file.
related codes
I"ve streamlined the code as follows:
ps: needs to be saved as a py file and run in terminal.
import multiprocessing as mp
import random
import time
def generater(a,b,tick):-sharplist
counter=0
while True:
time.sleep(1)
a.append([random.uniform(1,5),random.uniform(1,5),random.uniform(1,5),random.uniform(1,5)])
counter+=1
print("generate says",a[:])
if counter%5==0:
b.append(a[:])
tick.value=1-sharpprinter
for _ in a:
a.remove(_)
def printer(b,tick):-sharpa
while True:
if tick==1:
time.sleep(1)
print("printer says",b[:])
tick.value=0
for _ in b:
b.remove(_)
if __name__=="__main__":
tick=mp.Value("i",0)
a=mp.Manager().list()
b=mp.Manager().list()
p1=mp.Process(target=generater,args=(a,b,tick))
p2=mp.Process(target=printer,args=(b,tick))
p1.start()
p2.start()
I hope God criticizes and corrects. Thank you.