write.py
from multiprocessing import shared_memory
import time
a = shared_memory.ShareableList(['no'], name='123') # 创建共享内存,并且写值
count = 0
while True:
time.sleep(0.1)
count += 1
print(count)
if a[0] == 'yes':
break
if count >= 100:
break
a.shm.close()
a.shm.unlink()
update.py
from multiprocessing import shared_memory
a = shared_memory.ShareableList(name='123') # 更新共享内存
a[0] = 'yes'
参考:https://docs.python.org/3/library/multiprocessing.shared_memory.html