diff --git a/voussoirkit/threadpool.py b/voussoirkit/threadpool.py index 66d2069..8d7fe9b 100644 --- a/voussoirkit/threadpool.py +++ b/voussoirkit/threadpool.py @@ -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