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. 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). 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. 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 . That will be used for exhanging objects between processes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.