From b85173cec8fef3c8f21cdcfab71a4c1372140ea5 Mon Sep 17 00:00:00 2001 From: Kyle Smith Date: Tue, 5 Feb 2019 15:51:06 -0500 Subject: [PATCH] define __len__() to show number of active coroutines --- asyncio_pool/base_pool.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/asyncio_pool/base_pool.py b/asyncio_pool/base_pool.py index 865bc70..35da35b 100644 --- a/asyncio_pool/base_pool.py +++ b/asyncio_pool/base_pool.py @@ -39,6 +39,9 @@ async def __aenter__(self): async def __aexit__(self, ext_type, exc, tb): await self.join() + def __len__(self): + return len(self._waiting) + self.n_active + @property def n_active(self): '''Counts active coroutines''' @@ -52,7 +55,7 @@ def is_empty(self): @property def is_full(self): '''Returns `True` if `size` coroutines are already active.''' - return self.size <= len(self._waiting) + self.n_active + return self.size <= len(self) async def join(self): '''Waits (blocks) for all spawned coroutines to finish, both active and