@@ -104,6 +104,7 @@ class TransferRegistry:
104104
105105 def __init__ (self ) -> None :
106106 self ._lock = threading .Lock ()
107+ self ._cv = threading .Condition (self ._lock )
107108 self ._transfers : Dict [str , Dict [str , Any ]] = {}
108109 self ._last_activity : Dict [str , float ] = {}
109110 self ._inflight : Dict [str , int ] = {}
@@ -127,7 +128,9 @@ def unregister(self, transfer_id: str) -> int:
127128 logging .error ("unregister rejected invalid transfer_id=%r" , transfer_id )
128129 with self ._lock :
129130 return len (self ._transfers )
130- with self ._lock :
131+ with self ._cv :
132+ while self ._inflight .get (safe_id , 0 ) > 0 :
133+ self ._cv .wait ()
131134 self ._transfers .pop (safe_id , None )
132135 self ._last_activity .pop (safe_id , None )
133136 self ._inflight .pop (safe_id , None )
@@ -168,12 +171,13 @@ def request_lifecycle(self, transfer_id: str) -> Iterator[None]:
168171 yield
169172 finally :
170173 now = time .monotonic ()
171- with self ._lock :
174+ with self ._cv :
172175 count = self ._inflight .get (safe_id , 1 ) - 1
173176 if count <= 0 :
174177 self ._inflight .pop (safe_id , None )
175178 if safe_id in self ._transfers :
176179 self ._last_activity [safe_id ] = now
180+ self ._cv .notify_all ()
177181 else :
178182 self ._inflight [safe_id ] = count
179183
0 commit comments