由大卫·巴德雷创作的精致的婚礼

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中的代码与原始代码基本相同,我只做了两件事:

  1. 修复未将dtype参数传递给下游调用的错误
  2. 使用black
  3. 重新格式化代码

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Android:如何写入特定行,Java   Java中从欧元货币字符串中删除空格的数字   Java非均匀多维数组   解密AES时出现java空指针异常   java ConcurrentModificationException尝试移除列表上的所有内容时(非迭代)   Java数学库计算日志   java ISO8601,使用Jackson以毫秒表示json   避免副作用的java最佳实践   java获取JMeterException:调用bsh方法时出错:未定义参数:saa。使用beanshell取样器时   使用javascript将会话从一个jsp页面传输到另一个jsp页面   java在列表中组合相邻元素   java多行JTextPane   java Hibernate映射文件连接两个表而不定义关系?   如何使用Ajax、Java和Spring框架将文件从网页上传到Google云存储   多线程多线程Java中producerconsumer代码的多线程没有提供正确的输出?