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

相关推荐
小白教程1 分钟前
Python连接MySQL数据库图文教程,Python连接数据库MySQL入门教程
数据库·python·mysql·python链接数据库·python链接mysql
weixin_307779132 分钟前
PySpark实现GROUP BY WITH CUBE和WITH ROLLUP的分类汇总功能
大数据·开发语言·python·spark
不太会写32 分钟前
基于Python+django+mysql旅游数据爬虫采集可视化分析推荐系统
python·推荐算法
呱牛do it1 小时前
Python Matplotlib图形美化指南
开发语言·python·matplotlib
pianmian11 小时前
python制图之小提琴图
开发语言·python·信息可视化
橙子小哥的代码世界1 小时前
【机器学习】【KMeans聚类分析实战】用户分群聚类详解——SSE、CH 指数、SC全解析,实战电信客户分群案例
人工智能·python·机器学习·kmeans·数据科学·聚类算法·肘部法
计算机徐师兄1 小时前
Python基于Flask的豆瓣Top250电影数据可视化分析与评分预测系统(附源码,技术说明)
python·flask·豆瓣top250电影数据可视化·豆瓣top250电影评分预测·豆瓣电影数据可视化分析系统·豆瓣电影评分预测系统·豆瓣电影数据
k layc1 小时前
【论文解读】《Training Large Language Models to Reason in a Continuous Latent Space》
人工智能·python·机器学习·语言模型·自然语言处理·大模型推理
阿正的梦工坊1 小时前
Sliding Window Attention(滑动窗口注意力)解析: Pytorch实现并结合全局注意力(Global Attention )
人工智能·pytorch·python
喜-喜2 小时前
Python pip 缓存清理:全面方法与操作指南
python·缓存·pip