File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed
Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -181,22 +181,24 @@ async def acquire(self):
181181 self ._locked = True
182182 return True
183183
184- _waiters = self ._waiters
185184 fut = self ._loop .create_future ()
186- _waiters .append (fut )
185+ self ._waiters .append (fut )
186+
187+ # Finally block should be called before the CancelledError
188+ # handling as we don't want CancelledError to call
189+ # _wake_up_first() and attempt to wake up itself.
187190 try :
188191 try :
189192 await fut
190193 finally :
191- _waiters .remove (fut )
194+ self . _waiters .remove (fut )
192195 except futures .CancelledError :
193196 if not self ._locked :
194197 self ._wake_up_first ()
195198 raise
196199
197200 self ._locked = True
198201 return True
199-
200202
201203 def release (self ):
202204 """Release a lock.
@@ -221,12 +223,11 @@ def _wake_up_first(self):
221223 fut = next (iter (self ._waiters ))
222224 except StopIteration :
223225 return
224-
226+
225227 if not fut .done ():
226228 fut .set_result (True )
227229
228230
229-
230231class Event :
231232 """Asynchronous equivalent to threading.Event.
232233
You can’t perform that action at this time.
0 commit comments