Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.

Commit 774fb89

Browse files
committed
optimistic locking
1 parent 3871e81 commit 774fb89

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

proto/marshal/marshal.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,15 @@ def __new__(cls, *, name: str):
267267
marshals with the same ``name`` argument will provide the
268268
same marshal each time.
269269
"""
270-
with cls._instances_lock:
271-
klass = cls._instances.get(name)
272-
if klass is None:
273-
klass = super().__new__(cls)
274-
instances_copy = cls._instances.copy()
275-
instances_copy[name] = klass
276-
cls._instances = instances_copy
270+
klass = cls._instances.get(name)
271+
if klass is None:
272+
with cls._instances_lock:
273+
klass = cls._instances.get(name)
274+
if klass is None:
275+
klass = super().__new__(cls)
276+
instances_copy = cls._instances.copy()
277+
instances_copy[name] = klass
278+
cls._instances = instances_copy
277279

278280
return klass
279281

0 commit comments

Comments
 (0)