我有几个函数可以从共享内存中读取和写入数据,它们是通过while循环执行的。
例如,
def functionA():
while True:
# read data from shared memory
# manipulate data and write again to shared memory
def functionB():
while True:
# read data from shared memory at the same time with functionA()
# manipulate data (different way with functionA()) and write to shared memory(also different)
在这种情况下,如何在主函数中执行两个函数?
我尝试了 multiprocess ,如下所示
if __name__ == '__main__':
A = Process(target=functionA)
B = Process(target=functionB)
A.start()
B.start()
A.join()
B.join()
它不起作用