python3.8 新增功能 共享内存

2022-05-26  本文已影响0人  技术创造未来

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

上一篇 下一篇

猜你喜欢

热点阅读