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

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第三方库


热门话题
Java:如何使用另一个类中的对象   如何在Java中迭代旁遮普语(阿拉伯语)?   类Java嵌套ArrayList返回对象   java正则表达式以匹配“:”之后包含的字符串   java为什么main()很好地显示“Lukaku”并包含_names()返回null?   java嵌套循环,无法理解如何编写此代码   java使用maven动物嗅探器插件检查自己的API   java上传的文件创建保存以备将来在GWT服务器端使用   java转换为Dalvik格式失败65536限制   Java后端的javascript最佳RIA工具   amazon web服务如何将tar文件从amazonS3 bucket提取到Java中的另一个s3   java如何在hibernate搜索中实现对int值的搜索?   使用Maven初始化引导层JavaFX时发生java错误   java Google登录API例外:10:   java Glassfish 3.1.2加载本机库(.dll)   java在join操作中使用TumblingWindow,但没有将任何元素传输到my JoinFunction   IBatis+Java:检索HashMap   多线程java与scala在单独线程上读取文件