Make running_count and unfinished_count @property.
This commit is contained in:
parent
13f19719b2
commit
46e6e82fa0
1 changed files with 9 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue