import asyncio from aiohttp import ClientRequest, ClientResponse, ClientHandlerType class Semaphore(asyncio.Semaphore): async def __call__(self, req: ClientRequest, handler: ClientHandlerType) -> ClientResponse: async with self: return await handler(req)