@@ -156,6 +156,12 @@ def __str__(self) -> str:
156
156
)
157
157
158
158
159
+ @dataclass (frozen = True , slots = True )
160
+ class UnlockCalled (Event ):
161
+ def __str__ (self ) -> str :
162
+ return "An `unlock` method has been called."
163
+
164
+
159
165
"""
160
166
Broker
161
167
"""
@@ -179,7 +185,7 @@ def is_locked(self) -> bool:
179
185
raise NotImplementedError
180
186
181
187
@abstractmethod
182
- def unlock (self ) -> Self :
188
+ def unsafe_unlocking (self ) -> None :
183
189
raise NotImplementedError
184
190
185
191
@abstractmethod
@@ -289,12 +295,10 @@ def update[T](self, updater: Updater[T]) -> Self:
289
295
290
296
return self
291
297
292
- def unlock (self ) -> Self :
298
+ def unsafe_unlocking (self ) -> None :
293
299
for injectable in self .__injectables :
294
300
injectable .unlock ()
295
301
296
- return self
297
-
298
302
async def all_ready (self ) -> None :
299
303
for injectable in self .__injectables :
300
304
if injectable .is_locked :
@@ -802,11 +806,17 @@ def change_priority(self, module: Module, priority: Priority | PriorityStr) -> S
802
806
return self
803
807
804
808
def unlock (self ) -> Self :
805
- for broker in self .__brokers :
806
- broker .unlock ()
809
+ event = UnlockCalled ()
810
+
811
+ with self .dispatch (event , lock_bypass = True ):
812
+ self .unsafe_unlocking ()
807
813
808
814
return self
809
815
816
+ def unsafe_unlocking (self ) -> None :
817
+ for broker in self .__brokers :
818
+ broker .unsafe_unlocking ()
819
+
810
820
def load_profile (self , * names : str ) -> ContextManager [Self ]:
811
821
modules = (self .from_name (name ) for name in names )
812
822
self .unlock ().init_modules (* modules )
@@ -839,8 +849,9 @@ def on_event(self, event: Event, /) -> ContextManager[None]:
839
849
return self .dispatch (self_event )
840
850
841
851
@contextmanager
842
- def dispatch (self , event : Event ) -> Iterator [None ]:
843
- self .__check_locking ()
852
+ def dispatch (self , event : Event , * , lock_bypass : bool = False ) -> Iterator [None ]:
853
+ if not lock_bypass :
854
+ self .__check_locking ()
844
855
845
856
with self .__channel .dispatch (event ):
846
857
try :
0 commit comments