python多进程内存共享_Python—并发编程04多进程内存共享,python,间,的
Manaegr實(shí)現(xiàn)數(shù)據(jù)共享
導(dǎo)入 :from multiprocessing import Manager
實(shí)例化:m= Manager()
num = m.dict( {鍵 :? 值} )
num = m.list( [1, 2, 3] )
程序示例:
from multiprocessing import Manager,Process
def fun(num):
num[0] = 0
print('子進(jìn)程中num:', num)
if __name__ == '__main__':
m = Manager()
num = m.list([1, 2, 3])
print('最初的mun:', num)
p = Process(target=fun, args=(num,))
p.start()
p.join() # 子進(jìn)程運(yùn)行完父進(jìn)程才能運(yùn)行
print('父進(jìn)程中num:', num)
運(yùn)行結(jié)果:
最初的mun: [1, 2, 3]
子進(jìn)程中num: [0, 2, 3]
父進(jìn)程中num: [0, 2, 3]
Value實(shí)現(xiàn)數(shù)據(jù)共享
導(dǎo)入 :from multiprocessing import Value
實(shí)例化:xxx
xxx
xxxx
總結(jié)
以上是生活随笔為你收集整理的python多进程内存共享_Python—并发编程04多进程内存共享,python,间,的的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python函数可以提高运行效率吗_py
- 下一篇: websocket python爬虫_p