From 0319deba23ef34b16b4ec7efc8c13869f20eb1fc Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Tue, 10 Sep 2019 15:00:55 +0200 Subject: [PATCH] no semaphore --- openslides/utils/redis.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/openslides/utils/redis.py b/openslides/utils/redis.py index ebc05bd45..e96dd68a2 100644 --- a/openslides/utils/redis.py +++ b/openslides/utils/redis.py @@ -21,7 +21,7 @@ else: logger.info(f"Redis address {redis_address}") pool = ConnectionPool({"address": redis_address}) -semaphore = asyncio.Semaphore(100) +counter = 0 class RedisConnectionContextManager: @@ -32,7 +32,11 @@ class RedisConnectionContextManager: # TODO: contextlib.asynccontextmanager can be used in python 3.7 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() return self.conn @@ -44,7 +48,8 @@ class RedisConnectionContextManager: pool.push(self.conn) self.conn = None - semaphore.release() + global counter + counter -= 1 def get_connection() -> RedisConnectionContextManager: