From b7a2c3b19b229b19dbbff9ca91dd5f6f2b63d30a Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 12 Feb 2020 17:29:29 -0800 Subject: [PATCH] Simplify pool.join logic by just calling each job's join. --- voussoirkit/threadpool.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/voussoirkit/threadpool.py b/voussoirkit/threadpool.py index 5bf286a..1bbf395 100644 --- a/voussoirkit/threadpool.py +++ b/voussoirkit/threadpool.py @@ -70,8 +70,9 @@ class ThreadPool: ''' When a job finishes, it will call here. ''' - if self.closed or self.paused: + if self.paused: return + self.clear_done_and_start_jobs() def assert_not_closed(self): @@ -136,15 +137,9 @@ class ThreadPool: and block until all jobs are complete. ''' self.closed = True - self.job_manager_lock.acquire() - while self.unfinished_count() > 0: - print('round') - for job in self.jobs: - if job.thread: - print(job) - job.thread.join() - self._clear_done_and_start_jobs() - self.job_manager_lock.release() + self.clear_done_and_start_jobs() + 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)