44from types import TracebackType
55from typing import Annotated
66
7+ from common_library .basic_types import DEFAULT_FACTORY
78from pydantic import (
89 BaseModel ,
910 Field ,
@@ -89,6 +90,13 @@ class DistributedSemaphore(BaseModel):
8990 datetime .timedelta | None ,
9091 Field (description = "Maximum time to wait when blocking" ),
9192 ] = DEFAULT_SOCKET_TIMEOUT
93+ instance_id : Annotated [
94+ str ,
95+ Field (
96+ description = "Unique instance identifier" ,
97+ default_factory = lambda : f"{ uuid .uuid4 ()} " ,
98+ ),
99+ ] = DEFAULT_FACTORY
92100
93101 _acquire_script : AsyncScript
94102 _count_script : AsyncScript
@@ -110,15 +118,6 @@ def __init__(self, **data) -> None:
110118 RENEW_SEMAPHORE_SCRIPT
111119 )
112120
113- # Computed fields (read-only, automatically calculated)
114- @computed_field # type: ignore[prop-decorator]
115- @property
116- def instance_id (self ) -> str :
117- """Unique identifier for this semaphore instance."""
118- if not hasattr (self , "_instance_id" ):
119- self ._instance_id = str (uuid .uuid4 ())
120- return self ._instance_id
121-
122121 @computed_field # type: ignore[prop-decorator]
123122 @property
124123 def semaphore_key (self ) -> str :
0 commit comments