executive_smach icon indicating copy to clipboard operation
executive_smach copied to clipboard

State machines cannot be pickled

Open InigoMoreno opened this issue 4 years ago • 0 comments

I was trying to pickle a State machine in order to save it on a file to be executed later and I saw that it cannot be pickled due to the _state_transitioning_lock variable. This could be fixed by adding the following to the state_machine class:

    def __getstate__(self):
        return {k:v for (k, v) in self.__dict__.items() if k is not "_state_transitioning_lock"}

    def __setstate__(self, d):
        self.__dict__ = d
        self._state_transitioning_lock = threading.Lock()

InigoMoreno avatar Aug 05 '21 08:08 InigoMoreno