1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 02:00:45 +00:00

target: Replace Target.__copy__ by __getstate__

__getstate__ is also used by the copy module, but allows pickling the
class as well. This is useful when using the multiprocessing API, which
requires pickling the Target object to send it to the new process.
This commit is contained in:
Douglas Raillard 2021-11-03 10:41:47 +00:00 committed by Marc Bonnici
parent 77f0b1f06d
commit a65189f028

View File

@ -336,13 +336,14 @@ class Target(object):
if connect: if connect:
self.connect() self.connect()
def __copy__(self): def __getstate__(self):
new = self.__class__.__new__(self.__class__) return {
new.__dict__ = self.__dict__.copy() k: v
# Avoid sharing the connection instance with the original target, so for k, v in self.__dict__.items()
# that each target can live its own independent life # Avoid sharing the connection instance with the original target,
del new.__dict__['_conn'] # so that each target can live its own independent life
return new if k != '_conn'
}
# connection and initialization # connection and initialization