Skip to content

Commit 55e6adf

Browse files
authored
🐛 make throttle lazy init
1 parent d2f8314 commit 55e6adf

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

githubkit/throttling.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,15 @@ async def async_acquire(self, request: httpx.Request) -> AsyncGenerator[None, An
3535
class LocalThrottler(BaseThrottler):
3636
def __init__(self, max_concurrency: int) -> None:
3737
self.max_concurrency = max_concurrency
38-
self.semaphore = threading.Semaphore(max_concurrency)
38+
self._semaphore: Optional[threading.Semaphore] = None
3939
self._async_semaphore: Optional[anyio.Semaphore] = None
4040

41+
@property
42+
def semaphore(self) -> threading.Semaphore:
43+
if self._semaphore is None:
44+
self._semaphore = threading.Semaphore(self.max_concurrency)
45+
return self._semaphore
46+
4147
@property
4248
def async_semaphore(self) -> anyio.Semaphore:
4349
if self._async_semaphore is None:

0 commit comments

Comments
 (0)