我想将以下代码分成两个python脚本。负责更新myVar
的人。另一个接收更新的myVar
。
import multiprocessing
def func(myVar):
myVar = 2
if __name__ == "__main__":
myVar = multiprocessing.Value('d',2) #update myVar from the child process
p = multiprocessing.Process(target = func, args = (myVar,))
p.start()
p.join()
print(myVar) #get the updated myVar
所需结构为: update_myVar.py
def func(myVar):
myVar = 2
#if __name__ == "__main__": #spawn child process for main.py's main()
myVar = multiprocessing.Value('d',2) #update myVar from the child process
p = multiprocessing.Process(target = func, args = (myVar,))
p.start()
p.join()
和 main.py
if __name__ == "__main__":
print(myVar)
谢谢!