no semaphore

This commit is contained in:
FinnStutzenstein 2019-09-10 15:00:55 +02:00
parent cdfaf1f313
commit 0319deba23

View File

@ -21,7 +21,7 @@ else:
logger.info(f"Redis address {redis_address}") logger.info(f"Redis address {redis_address}")
pool = ConnectionPool({"address": redis_address}) pool = ConnectionPool({"address": redis_address})
semaphore = asyncio.Semaphore(100) counter = 0
class RedisConnectionContextManager: class RedisConnectionContextManager:
@ -32,7 +32,11 @@ class RedisConnectionContextManager:
# TODO: contextlib.asynccontextmanager can be used in python 3.7 # TODO: contextlib.asynccontextmanager can be used in python 3.7
async def __aenter__(self) -> "aioredis.RedisConnection": async def __aenter__(self) -> "aioredis.RedisConnection":
await semaphore.acquire() global counter
while counter > 100:
await asyncio.sleep(0.1)
counter += 1
self.conn = await pool.pop() self.conn = await pool.pop()
return self.conn return self.conn
@ -44,7 +48,8 @@ class RedisConnectionContextManager:
pool.push(self.conn) pool.push(self.conn)
self.conn = None self.conn = None
semaphore.release() global counter
counter -= 1
def get_connection() -> RedisConnectionContextManager: def get_connection() -> RedisConnectionContextManager: