问题标签 [multiprocessing-manager]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
62 浏览

python - 使用列表子类的多处理 manager.list

我正在尝试在调用 manager.list 时使用我的列表子类。所以,我可以添加自己的方法,但它不起作用。是否有可能做到这一点?

0 投票
1 回答
125 浏览

python - Python多处理 - 在线程之间使用共享变量和管理器?

我正在使用Manager来自 pythonsmultiprocessing库的。我想在线程之间共享变量。

所以我有一个函数,这个函数在内部使用了一个这样的变量。由于 python 的多处理规则,我需要将Manager和 变量放在if __name__ == '__main__':. 是否有一种聪明的方法仍然可以访问变量status?下面的代码:

这给了我一个

有什么建议么?谢谢!

0 投票
0 回答
87 浏览

python - Manager.dict() 的读取速度太慢

我有一个大约 2 GB 的巨大 dict 变量。我正在对这个字典进行一些科学计算(只读)。但是,共享字典的阅读速度比普通字典慢很多,即使它可以节省大量内存。有没有更快的方法在多处理作业中共享只读数据?这是我的代码

结果是

0 投票
0 回答
59 浏览

python - Async(io) Process Proxy

I am looking for a way or a library to communicate asynchronously with an object an a different process. Here is an example where I want to put Solver on different processes, but still be able to communicate with the solver very often. The important thing here is, that initialization of the Solver is very expensive, so that it can only be done once per process and should live for many solve calls.

I hope you can understand what I want to achieve. multiprocessing.Manager seems similar to what I want to do, but I need non-blocking calls via the Proxy.

0 投票
1 回答
76 浏览

python-3.x - 如何在远程进程之间使用 Python3.9.2 multiprocessing.SyncManager?

我在有关远程进程之间数据同步的相关 Python 3.9.2 文档中对以下测试程序进行了建模。不过,据我所知,它实际上并没有用,所以我认为有些东西我不知道。该文档没有明确说明在远程进程之间部署 SyncManager 对象,但它们毕竟是 BaseManager 子类的实例,因此必须假设相同的技术应该可以工作。

在下面的代码之后,shell 输出显示了三个并发调用,这可能证明了我遇到的问题。尽管正在与服务器建立连接,但字典并未同步。问题是:为什么?

在第一个 shell 中,SyncManager 服务器启动:

让它继续运行,我在第二个 shell 中再次启动程序:

到目前为止,一切都很好。我让它运行并第三次调用。但是第三次​​调用对第二次调用做了什么一无所知。共享字典中没有“流”键:

我错过了什么?

(Python 3.9.2) (Linux 5.10.0-4-amd64 #1 SMP Debian 5.10.19-1 (2021-03-02) x86_64 GNU/Linux)

备注:通常,文档似乎假定所有 SyncManager 对象都将由名为“multiprocessing.Manager()”的快捷方式创建,该快捷方式不提供远程套接字通信的规范。我假设这些对象旨在被所有将使用它的进程分叉继承,正如我迄今为止发现的所有示例所示。但这不是我想要做的。

0 投票
0 回答
23 浏览

python-3.x - 在进程之间共享类的最佳方式

首先,我是多处理方面的新手,我来这里是为了向大家学习。我有几个文件在做类似的事情:

共享类.py:

我的进程.py:

主要.py:

我想在一种共享内存中定义一个共享类(在 SharedClass.py 中),它可以对 Main.py 和 MyProcess.py 文件进行读写。

我尝试使用Manager多处理,multiprocessing.array但我没有很好的结果,在一个文件中所做的更改没有反映在另一个文件中(也许我以错误的方式这样做)。

有任何想法吗?谢谢你。

0 投票
0 回答
119 浏览

python - 在 multiprocessing.Manager().dict() 上获取 ConnectionRefusedError [Errno 61]

长话短说,我试图multiprocessing.Manager().dict()在主线程中打印 a 的内容,但出现了一个奇怪的错误。

仅当池的数量大于20(是的,恰好20)并且仅在macOS(在 上完美运行Linux)时,我才遇到此错误。

眼镜:

附上最小错误码:

错误:

0 投票
0 回答
65 浏览

python - Why manager.dict and manager.list is slow and sometimes cause deadlock?

I want to load a huge dict/2d array in the father process and share it between child processes. All the child processes only need to read it without any other modification operations. Now I have several questions in terms of multiprocessing.pool and manager.(python3.6+linux) (1)Using a common dict or list will sometimes cause "cannot allocate memory" error, is this because the fork() mechanism in linux system? The huge dict will be copied 30 times in the memory if there are 30 processes, is that true? (2)I try to use manager to deal with this problem because it's more friendly to dict and array type. but it's extrmely slow and sometimes caused deadlock.(enough memory but 0 in cpu usage). How can I fix it?

#simplified version

(3) In another scenario, I want to define the manager.dict object as a global varieble and read it in the child process directly. Also, some modification will happen later in the father process. The implementation is similar as before, but again, it's extremely slow although only read happened. How can I fix it? Is there some other solutions? Thank you for any advices!

0 投票
1 回答
304 浏览

python - 两个脚本之间的 Python IPC 共享内存

我正在尝试为 Raspberry Pi3 开发应用程序。事实上2个应用程序。应用程序 1 将是一个简单的 gpio 读取,计算特定 gpio 输入变高的次数并登录到 file 。应用 2 将在屏幕上显示 GPIO 状态。我希望应用程序 1 持续运行并记录数据。这就是我将其与基于 UI 的应用程序分开的原因。现在我想从应用程序 1 中获取 gpio 状态 - 数据将是 pin1State、pin1HighCount、pin2State、pin2HighCount。所有这些都是整数。应用程序 2 应该从应用程序 1 获取数据并显示在基于 pyqt5 的 UI 屏幕中。我尝试在单独的 Docker 容器中跨 Python 脚本遵循这个示例 IPC 共享内存 但我发现它是一个基于字典的数据交换,而且它不是连续的或几乎是实时的。首先填充字典,然后加载到 server.py 我无法在其他地方找到有关此方法的太多信息。我喜欢不使用文件(临时或其他)的基于本地主机的套接字方法。但我无法获得连续数据。此外,是否可以使用列表甚至单个整数变量而不是字典。我担心通过不断更新(附加)到字典,如果脚本长时间运行我的代码如下Server.py,它可能会造成内存过载

客户端.py

0 投票
1 回答
81 浏览

python - 更改 Python 多处理管理器的衍生进程名称

我想使用 setproctitle 更改生成的多处理管理器 SyncManager 的进程名称,我尝试扩展 multiprocessing.managers.SyncManager:

但这似乎不起作用。知道怎么做吗?