Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cloudpickle/cloudpickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
import threading
import types
import typing
import uuid
import warnings
import weakref

Expand All @@ -94,6 +93,7 @@
_DYNAMIC_CLASS_TRACKER_BY_CLASS = weakref.WeakKeyDictionary()
_DYNAMIC_CLASS_TRACKER_BY_ID = weakref.WeakValueDictionary()
_DYNAMIC_CLASS_TRACKER_LOCK = threading.Lock()
_NEXT_DYNAMIC_CLASS_TRACKER_ID = 1 # do not use without _DYNAMIC_CLASS_TRACKER_LOCK

PYPY = platform.python_implementation() == "PyPy"

Expand All @@ -106,10 +106,14 @@


def _get_or_create_tracker_id(class_def):
global _NEXT_DYNAMIC_CLASS_TRACKER_ID
with _DYNAMIC_CLASS_TRACKER_LOCK:
class_tracker_id = _DYNAMIC_CLASS_TRACKER_BY_CLASS.get(class_def)
if class_tracker_id is None:
class_tracker_id = uuid.uuid4().hex
# We use a 32 bit hex string to remain compatible with the
# previous uuid4 hex string representation.
class_tracker_id = f"{_NEXT_DYNAMIC_CLASS_TRACKER_ID:032x}"
_NEXT_DYNAMIC_CLASS_TRACKER_ID += 1
_DYNAMIC_CLASS_TRACKER_BY_CLASS[class_def] = class_tracker_id
_DYNAMIC_CLASS_TRACKER_BY_ID[class_tracker_id] = class_def
return class_tracker_id
Expand Down