Seems like I found simlple solution that works for me:
So let's say we have class C
that was generated with SWIG, then we wrap it with
class PickalableC(C, PickalableSWIG):
def __init__(self, *args):
self.args = args
C.__init__(self)
where PickalableSWIG
is
class PickalableSWIG:
def __setstate__(self, state):
self.__init__(*state['args'])
def __getstate__(self):
return {'args': self.args}
Then
pickle.loads(pickle.dumps(C()))
fails, but
pickle.loads(pickle.dumps(PickalableC()))
succeeds =)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…