Skip to content

Commit 0011cd6

Browse files
docs: Document thread-safety rationale for codec registry
The global codec registry is effectively immutable after import: registration runs under Python's import lock, and the only runtime mutation (_load_entry_points) is idempotent under the GIL. Per-instance isolation is unnecessary since codecs are part of the type system, not connection-scoped state. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9d9d675 commit 0011cd6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/datajoint/codecs.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ class MyTable(dj.Manual):
4343

4444
logger = logging.getLogger(__name__.split(".")[0])
4545

46-
# Global codec registry - maps name to Codec instance
46+
# Global codec registry - maps name to Codec instance.
47+
#
48+
# Thread safety: This registry is effectively immutable after import.
49+
# Registration happens in __init_subclass__ during class definition, which is
50+
# serialized by Python's import lock. The only runtime mutation is
51+
# _load_entry_points(), which is idempotent and guarded by a bool flag;
52+
# under CPython's GIL, concurrent calls may do redundant work but cannot
53+
# corrupt the dict. Codecs are part of the type system (tied to code, not to
54+
# any particular connection or tenant), so per-instance isolation is unnecessary.
4755
_codec_registry: dict[str, Codec] = {}
4856
_entry_points_loaded: bool = False
4957

0 commit comments

Comments
 (0)