Python 多进程中使用共享内存在进程之间共享数据,python进程,在python的muti
Python 多进程中使用共享内存在进程之间共享数据,python进程,在python的muti
在python的mutiprocessing中,有Value和Array类,可以和共享内存交互,来实现在进程之间共享数据。
from multiprocessing import Process, Value, Arraydef f(n, a): n.value = 3.1415927 for i in range(len(a)): a[i] = -a[i]if __name__ == '__main__': num = Value('d', 0.0) arr = Array('i', range(10)) p = Process(target=f, args=(num, arr)) p.start() p.join() print num.value print arr[:]
Server process:
from multiprocessing import Process, Managerdef f(d, l): d[1] = '1' d['2'] = 2 d[0.25] = None l.reverse()if __name__ == '__main__': manager = Manager() d = manager.dict() l = manager.list(range(10)) p = Process(target=f, args=(d, l)) p.start() p.join() print d print l
关于Array文档请参考: http://docs.python.org/library/array.html
相关内容
- Python多进程multiprocessing使用示例,,由于要做把一个多线
- 在Python 多进程中使用signal,pythonsignal,下面的代码我只
- Python初学教程:元组 使用示例,python示例,python 元组
- python使用qrcode包生成二维码,pythonqrcode,python使用qrco
- Python初学教程:Python dict使用示例,pythondict,Python Dict
- Python初学教程:读取文件,,Python 读取文件#
- Python 操作 Sqlite3教程,pythonsqlite3,Python编程语言从出
- Python生成RSS,pythonrss,心血来潮要搞下pytho
- Python解析RSS,pythonrss,首先需要安装RSS解析的
- python webpy purge nginx fastcgi cache 代码实现,webpynginx,前几
评论关闭