修改multiprocessing.Manager().dict()中对象的变量的值

类

复制代码
class SystemSta:
    def __init__(self):
        self.AllJointsFindedHome = False

创建字典

复制代码
manager = multiprocessing.Manager()
shared_data = manager.dict()
shared_data['SystemSta'] = SystemSta()

更改字典中对象的变量的值

错误示范

复制代码
shared_data['SystemSta'].AllJointsFindedHome = False

在Python的multiprocessing模块中,multiprocessing.Manager().dict()中的对象不支持直接修改其属性。你试图修改shared_data['SystemSta'].AllJointsFindedHome,但是这个改变并没有被应用到shared_data里。为了解决这个问题,你可以在修改SystemSta对象后,再将其赋值回shared_data,如下所示:

复制代码
    temp = shared_data['SystemSta']
    temp.AllJointsFindedHome = True
    shared_data['SystemSta'] = temp

这样,当你修改SystemSta对象的属性后,这个改变就会被正确的应用到shared_data里。

相关推荐
蚰蜒螟31 分钟前
从内核启动到 Java NIO:一次 socket accept 的源码串联之旅
java·python·nio
高洁011 小时前
AI赋能产业升级与中美未来经济赛道博弈
人工智能·python·深度学习·机器学习·transformer
夜晚回家1 小时前
Python 原始字符串详解 | r 前缀到底让什么不再转义
开发语言·python
用户019027581612 小时前
如何用 Python 计算 EMV 简易波动指标?
python
第25小时记录2 小时前
[2026] Linux安装教程
运维·python
前端 贾公子3 小时前
LangGraph == 图的状态(State)管理 (中)
开发语言·数据库·python
the局外人4 小时前
FastAPI中jwt的基本使用与实践
后端·python·fastapi
mklpo1474 小时前
为不支持sse4.2命令集的老旧设备制作Win11 26H2系统镜像,2026-10-11。
运维·windows·python
GoldenSpider.AI4 小时前
用 AI 改流程之前先做「四桶」体检:9 次返工里 8 次靠规则就能消掉(附 Python 发布前校验器)
人工智能·python·自动化·ai智能体