Skip to content

Commit

Permalink
🐛 make throttle lazy init
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored Dec 14, 2024
1 parent d2f8314 commit 55e6adf
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion githubkit/throttling.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ async def async_acquire(self, request: httpx.Request) -> AsyncGenerator[None, An
class LocalThrottler(BaseThrottler):
def __init__(self, max_concurrency: int) -> None:
self.max_concurrency = max_concurrency
self.semaphore = threading.Semaphore(max_concurrency)
self._semaphore: Optional[threading.Semaphore] = None
self._async_semaphore: Optional[anyio.Semaphore] = None

@property
def semaphore(self) -> threading.Semaphore:
if self._semaphore is None:
self._semaphore = threading.Semaphore(self.max_concurrency)
return self._semaphore

@property
def async_semaphore(self) -> anyio.Semaphore:
if self._async_semaphore is None:
Expand Down

0 comments on commit 55e6adf

Please sign in to comment.