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

相关推荐
BatyTao13 分钟前
Python从零起步-数据容器
开发语言·python
所谓伊人,在水一方33342 分钟前
【Python数据科学实战之路】第5章 | 数据可视化基础:用Matplotlib讲好数据故事
python·信息可视化·matplotlib
NGC_66111 小时前
Java基础面试题2
java·开发语言·python
vx-程序开发1 小时前
springboot具备推荐和预警机制的大学生兼职平台的设计与实现-计算机毕业设计源码17157
java·c++·spring boot·python·spring·django·php
EnCi Zheng2 小时前
11a. 阿里云大模型API调用基础
人工智能·python·阿里云·云计算
MoRanzhi12032 小时前
Pillow 图像算术运算与通道计算
图像处理·人工智能·python·计算机视觉·pillow·图像差异检测·图像算术运算
怪侠_岭南一只猿3 小时前
爬虫阶段三实战练习题二:使用 Selenium 模拟爬取拉勾网职位表
css·爬虫·python·selenium·html
前端付豪3 小时前
自动学习建议解决薄弱知识点
前端·python·openai
deephub3 小时前
LangGraph vs Semantic Kernel:状态图与内核插件的两条技术路线对比
人工智能·python·深度学习·大语言模型·agent
与虾牵手3 小时前
多轮对话 API 怎么实现?从原理到代码,踩完坑我总结了这套方案
python·aigc·ai编程