File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
packages/service-library/src/servicelib/redis Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -450,7 +450,7 @@ async def _periodic_reacquisition(
450450 started : asyncio .Event ,
451451 cancellation_event : asyncio .Event ,
452452 ) -> None :
453- if cancellation_event .is_set ():
453+ if cancellation_event .is_set () or asyncio . current_task (). cancelled () :
454454 raise asyncio .CancelledError
455455 if not started .is_set ():
456456 started .set ()
@@ -475,10 +475,11 @@ async def _periodic_reacquisition(
475475 name = f"semaphore/auto_reacquisition_task_{ semaphore .key } _{ semaphore .instance_id } " ,
476476 )
477477 await auto_reacquisition_started .wait ()
478-
479- yield semaphore
480- cancellation_event .set () # NOTE: this ensure cancellation is effective
481- await cancel_wait_task (auto_reacquisition_task )
478+ try :
479+ yield semaphore
480+ finally :
481+ cancellation_event .set () # NOTE: this ensure cancellation is effective
482+ await cancel_wait_task (auto_reacquisition_task )
482483 except BaseExceptionGroup as eg :
483484 semaphore_errors , other_errors = eg .split (SemaphoreError )
484485 if other_errors :
You can’t perform that action at this time.
0 commit comments