[英]Getter on a object inheriting from multiprocessing.Process
As far is i know a object inheriting from multiprocessing.Process copies all it's variables into different memory to run as a separate Process.据我所知,从多处理继承的 object 将其所有变量复制到不同的 memory 中以作为单独的进程运行。 There are different ways of safely exchanging data between processes, however, it would still be possible to just call a getter in this object (like the example below).
在进程之间安全地交换数据有不同的方法,但是,仍然可以在这个 object 中调用一个 getter(如下例所示)。 How unsafe is that?
这有多不安全? And does this cause a major slowdown?
这会导致大幅放缓吗?
I just want to put some "metadata" into this object (name, priority, stuff like that), which is constant.我只想将一些“元数据”放入这个 object(名称、优先级等)中,这是不变的。 If there is a better way to do that.
如果有更好的方法来做到这一点。 I would be interested in that as well.
我也会对此感兴趣。
class P(multiprocessing.Process):
def __init__(self, priority: int):
multiprocessing.Process.__init__(self)
self.priority = priority
def getPriority(self):
return self.priority
p = P()
p.start()
p.getPriority()
You can use it, it's pretty fast and it won't be trivial to implement something faster than build in solution.您可以使用它,它非常快,而且实现比内置解决方案更快的东西并非易事。 Internally the object sharing is done via object pickling .
在内部,object 共享是通过 object 酸洗完成的。 That will be used for exhanging objects between processes.
这将用于在进程之间交换对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.