修改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里。

相关推荐
EnCi Zheng6 小时前
09-斯坦福CS336作业 [特殊字符]
人工智能·pytorch·python·深度学习·神经网络
端平入洛6 小时前
Python 切片赋值 vs 普通赋值:你真的改了那个 list 吗?
python
smj2302_796826527 小时前
解决leetcode第3934题最短唯一子数组
数据结构·python·算法·leetcode
WL_Aurora7 小时前
Python 算法基础篇之查找算法(二):斐波那契查找、分块查找与哈希查找
python·哈希算法·查找
牙牙要健康7 小时前
Windows 下为 VSCode 配置 Anaconda:从零安装 Python 环境到完整配置教程
windows·vscode·python
财经资讯数据_灵砚智能7 小时前
基于全球经济类多源新闻的NLP情感分析与数据可视化(夜间-次晨)2026年5月17日
大数据·人工智能·python·信息可视化·自然语言处理
databook7 小时前
切线的魔法:用 SymPy 和 Manim 轻松搞定导数动画
python·数学·动效
程序员榴莲7 小时前
Python 正则表达式入门:从匹配手机号到提取文本内容
python·正则表达式
程序员榴莲8 小时前
Python 中的 @property:像访问属性一样调用方法
开发语言·前端·python
坐吃山猪8 小时前
【Nanobot】README04_LEVEL2 提供商系统设计
python·源码·agent·nanobot