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:
parent
77f0b1f06d
commit
a65189f028
@ -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
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user