Skip to content

Commit 948ec2f

Browse files
committed
minor
1 parent edcc44d commit 948ec2f

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

packages/service-library/src/servicelib/redis/_semaphore.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,9 @@ async def acquire(self) -> bool:
183183
if timeout_seconds is not None:
184184
elapsed = asyncio.get_event_loop().time() - start_time
185185
if elapsed >= timeout_seconds:
186-
if self.blocking:
187-
raise SemaphoreAcquisitionError(
188-
name=self.key, capacity=self.capacity
189-
)
190-
return False
186+
raise SemaphoreAcquisitionError(
187+
name=self.key, capacity=self.capacity
188+
)
191189

192190
# Wait a bit before retrying
193191
await asyncio.sleep(0.1)
@@ -364,9 +362,8 @@ async def _wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
364362
blocking_timeout=blocking_timeout,
365363
)
366364

367-
# Acquire the semaphore
368-
if not await semaphore.acquire() and not blocking:
369-
# Non-blocking mode, semaphore not available
365+
# Acquire the semaphore first
366+
if not await semaphore.acquire():
370367
raise SemaphoreAcquisitionError(
371368
name=semaphore_key, capacity=semaphore_capacity
372369
)

0 commit comments

Comments
 (0)