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

相关推荐
用户8356290780512 分钟前
Python 实现 Excel 条件格式自动化
后端·python
深蓝电商API44 分钟前
Scrapy管道Pipeline深度解析:多方式数据持久化
爬虫·python·scrapy
噎住佩奇1 小时前
(Win11系统)搭建Python爬虫环境
爬虫·python
basketball6161 小时前
python 的对象序列化
开发语言·python
rgeshfgreh1 小时前
Python流程控制:从条件到循环实战
前端·数据库·python
luoluoal1 小时前
基于python大数据的电影市场预测分析(源码+文档)
python·mysql·django·毕业设计·源码
幻云20102 小时前
Python深度学习:从入门到实战
人工智能·python
Zoey的笔记本2 小时前
敏捷与稳定并行:Scrum看板+BPM工具选型指南
大数据·前端·数据库·python·低代码
开开心心就好3 小时前
图片格式转换工具,右键菜单一键转换简化
linux·运维·服务器·python·django·pdf·1024程序员节
骥龙3 小时前
1.2下、工欲善其事:物联网安全研究环境搭建指南
python·物联网·安全