Skip to content

Commit 2c8cdd1

Browse files
authored
Merge pull request #1 from smithk86/master
define __len__() to show number of active coroutines
2 parents b4902ac + b85173c commit 2c8cdd1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

asyncio_pool/base_pool.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ async def __aenter__(self):
3939
async def __aexit__(self, ext_type, exc, tb):
4040
await self.join()
4141

42+
def __len__(self):
43+
return len(self._waiting) + self.n_active
44+
4245
@property
4346
def n_active(self):
4447
'''Counts active coroutines'''
@@ -52,7 +55,7 @@ def is_empty(self):
5255
@property
5356
def is_full(self):
5457
'''Returns `True` if `size` coroutines are already active.'''
55-
return self.size <= len(self._waiting) + self.n_active
58+
return self.size <= len(self)
5659

5760
async def join(self):
5861
'''Waits (blocks) for all spawned coroutines to finish, both active and

0 commit comments

Comments
 (0)