Make running_count and unfinished_count @property.

This commit is contained in:
Ethan Dalool 2020-03-03 01:55:22 -08:00
parent 13f19719b2
commit 46e6e82fa0

View file

@ -45,7 +45,7 @@ class ThreadPool:
This function assumes that _job_manager_lock is acquired!!
You should call clear_done_and_start_jobs instead!
'''
available = self.max_size - self.running_count()
available = self.max_size - self.running_count
available = max(0, available)
if available == 0:
return
@ -75,6 +75,14 @@ class ThreadPool:
self.clear_done_and_start_jobs()
@property
def running_count(self):
return sum(1 for job in list(self._jobs) if job.status is RUNNING)
@property
def unfinished_count(self):
return sum(1 for job in list(self._jobs) if job.status in {PENDING, RUNNING})
def assert_not_closed(self):
'''
If the pool is closed (because you called `join`), raise PoolClosed.
@ -166,12 +174,6 @@ class ThreadPool:
for job in self._jobs:
job.join()
def running_count(self):
return sum(1 for job in list(self._jobs) if job.status is RUNNING)
def unfinished_count(self):
return sum(1 for job in list(self._jobs) if job.status in {PENDING, RUNNING})
class Job:
def __init__(self, pool, function, *, name=None, args=tuple(), kwargs=dict()):
self.pool = pool