diff --git a/plumpy/base/state_machine.py b/plumpy/base/state_machine.py index a3996d5a..e90cb827 100644 --- a/plumpy/base/state_machine.py +++ b/plumpy/base/state_machine.py @@ -286,6 +286,9 @@ def add_state_event_callback(self, hook: Hashable, callback: EVENT_CALLBACK_TYPE self._event_callbacks.setdefault(hook, []).append(callback) def remove_state_event_callback(self, hook: Hashable, callback: EVENT_CALLBACK_TYPE) -> None: + if getattr(self, '_closed', False): + # if the process is closed, then all callbacks have already been removed + return None try: self._event_callbacks[hook].remove(callback) except (KeyError, ValueError):