Skip to content

Commit

Permalink
refac: Improved support for pickle and deepcopy (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
fgmacedo authored Nov 30, 2024
1 parent e16e0ef commit 2977f83
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 23 deletions.
3 changes: 0 additions & 3 deletions statemachine/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,6 @@ def __init__(self) -> None:
self._registry: Dict[str, CallbacksExecutor] = defaultdict(CallbacksExecutor)
self.has_async_callbacks: bool = False

def clear(self):
self._registry.clear()

def __getitem__(self, key: str) -> CallbacksExecutor:
return self._registry[key]

Expand Down
20 changes: 0 additions & 20 deletions statemachine/statemachine.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import warnings
from copy import deepcopy
from inspect import isawaitable
from threading import Lock
from typing import TYPE_CHECKING
from typing import Any
from typing import Dict
Expand Down Expand Up @@ -129,24 +127,6 @@ def __repr__(self):
f"current_state={current_state_id!r})"
)

def __deepcopy__(self, memo):
deepcopy_method = self.__deepcopy__
lock = self._engine._processing
with lock:
self.__deepcopy__ = None
self._engine._processing = None
try:
cp = deepcopy(self, memo)
cp._engine._processing = Lock()
finally:
self.__deepcopy__ = deepcopy_method
cp.__deepcopy__ = deepcopy_method
self._engine._processing = lock
cp._callbacks.clear()
cp._register_callbacks([])
cp.add_listener(*cp._listeners.keys())
return cp

def __getstate__(self):
state = self.__dict__.copy()
state["_rtc"] = self._engine._rtc
Expand Down

0 comments on commit 2977f83

Please sign in to comment.