@@ -456,6 +456,7 @@ async def _periodic_reacquisition(
456456 started .set ()
457457 await semaphore .reacquire ()
458458
459+ lock_acquisition_time = None
459460 try :
460461 if not await semaphore .acquire ():
461462 raise SemaphoreAcquisitionError (name = key , instance_id = semaphore .instance_id )
@@ -516,15 +517,16 @@ async def _periodic_reacquisition(
516517 "Look for synchronouse code or the loop is very busy and cannot schedule the reacquisition task." ,
517518 )
518519 )
519- lock_release_time = arrow .utcnow ()
520- locking_time = lock_release_time - lock_acquisition_time
521- if locking_time > expected_lock_overall_time :
522- _logger .warning (
523- "Semaphore '%s' was held for %s by %s which is longer than expected (%s). "
524- "TIP: consider reducing the locking time by optimizing the code inside "
525- "the critical section or increasing the default locking time" ,
526- semaphore .key ,
527- locking_time ,
528- semaphore .instance_id ,
529- expected_lock_overall_time ,
530- )
520+ if lock_acquisition_time is not None :
521+ lock_release_time = arrow .utcnow ()
522+ locking_time = lock_release_time - lock_acquisition_time
523+ if locking_time > expected_lock_overall_time :
524+ _logger .warning (
525+ "Semaphore '%s' was held for %s by %s which is longer than expected (%s). "
526+ "TIP: consider reducing the locking time by optimizing the code inside "
527+ "the critical section or increasing the default locking time" ,
528+ semaphore .key ,
529+ locking_time ,
530+ semaphore .instance_id ,
531+ expected_lock_overall_time ,
532+ )
0 commit comments