python单例进入多处理 [英] python singleton into multiprocessing

查看:76
本文介绍了python单例进入多处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何在进程之间共享"singletonic"类的相同实例?

How can I code to share the same instance of a "singletonic" class among processes?

推荐答案

最好是将一个特定的进程指定为拥有该实例并专用于该实例.需要访问该实例的任何其他进程通过将消息通过队列(由多处理模块提供)或其他IPC机制用于消息传递,将消息发送给拥有进程来获取它,并通过类似的机制获取答案.

Best is to designate one specific process as owning that instance and dedicated to it; any other process requiring access to that instance obtains it by sending messages to the owning process via a Queue (as supplied by the multiprocessing module) or other IPC mechanisms for message passing, and gets answers back via similar mechanisms.

这篇关于python单例进入多处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆