mirror of
https://github.com/Garmelon/PFERD.git
synced 2026-04-13 07:55:05 +02:00
Clean up and fix conductor and limiter
Turns out you have to await an async lock, who knew...
This commit is contained in:
parent
c4fb92c658
commit
7e127cd5cc
2 changed files with 14 additions and 27 deletions
|
|
@ -1,7 +1,6 @@
|
|||
import asyncio
|
||||
from contextlib import asynccontextmanager
|
||||
# TODO If we upgrade to python 3.9, this context manager hint is deprecated
|
||||
from typing import AsyncContextManager, AsyncIterator
|
||||
from typing import AsyncIterator
|
||||
|
||||
|
||||
class Limiter:
|
||||
|
|
@ -9,12 +8,9 @@ class Limiter:
|
|||
self._semaphore = asyncio.Semaphore(limit)
|
||||
|
||||
@asynccontextmanager
|
||||
async def _context_manager(self) -> AsyncIterator[None]:
|
||||
async def limit(self) -> AsyncIterator[None]:
|
||||
await self._semaphore.acquire()
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
self._semaphore.release()
|
||||
|
||||
def limit(self) -> AsyncContextManager[None]:
|
||||
return self._context_manager()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue