由大卫·巴德雷创作的精致的婚礼
shmarra的Python项目详细描述
shmarray
shmarray是利用 多处理.sharedTypes。这是一个非常有用的小图书馆 大卫·巴德雷。我是在 https://github.com/lucastheis/parallel/blob/master/shmarray.py
尽管它很有用,但它不仅没有安装pip 包,但也包含年久失修的错误。
此回购协议是作为补救措施而创建的。
安装
pip install shmarray
用法
test.py
from multiprocessing import Process
import time
import shmarray
def worker(data):
while True:
data += 1
time.sleep(1)
def monitor(data):
while True:
print(data)
time.sleep(0.5)
data = shmarray.zeros(10)
procs = [
Process(target=worker, args=(data, )),
Process(target=monitor, args=(data, )),
]
for p in procs:
p.start()
for p in procs:
p.join()
结果:
$ python3 test.py [1. 1. 1. 1. 1. 1. 1. 1. 1. 1.][1. 1. 1. 1. 1. 1. 1. 1. 1. 1.][2. 2. 2. 2. 2. 2. 2. 2. 2. 2.][2. 2. 2. 2. 2. 2. 2. 2. 2. 2.][3. 3. 3. 3. 3. 3. 3. 3. 3. 3.][3. 3. 3. 3. 3. 3. 3. 3. 3. 3.][4. 4. 4. 4. 4. 4. 4. 4. 4. 4.][4. 4. 4. 4. 4. 4. 4. 4. 4. 4.][5. 5. 5. 5. 5. 5. 5. 5. 5. 5.][5. 5. 5. 5. 5. 5. 5. 5. 5. 5.][6. 6. 6. 6. 6. 6. 6. 6. 6. 6.][6. 6. 6. 6. 6. 6. 6. 6. 6. 6.] ...
后记
shmarray.py
中的代码与原始代码基本相同,我只做了两件事:
- 修复未将
dtype
参数传递给下游调用的错误 - 使用black 重新格式化代码