From a65189f0287dc11e5eda0a1acf858ad62a10f192 Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Wed, 3 Nov 2021 10:41:47 +0000 Subject: [PATCH] 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. --- devlib/target.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/devlib/target.py b/devlib/target.py index 80e4f4e..6e82e9a 100644 --- a/devlib/target.py +++ b/devlib/target.py @@ -336,13 +336,14 @@ class Target(object): if connect: self.connect() - def __copy__(self): - new = self.__class__.__new__(self.__class__) - new.__dict__ = self.__dict__.copy() - # Avoid sharing the connection instance with the original target, so - # that each target can live its own independent life - del new.__dict__['_conn'] - return new + def __getstate__(self): + return { + k: v + for k, v in self.__dict__.items() + # Avoid sharing the connection instance with the original target, + # so that each target can live its own independent life + if k != '_conn' + } # connection and initialization