self.wakeup_timeout = None
self.threads = []
- for i in range(self.nr_concurrent_jobs):
- self.spawn_new_thread(i)
+ self.spawn_all_threads()
self.start()
def spawn_new_thread(self, suffix):
self.threads.append(t)
+ def spawn_all_threads(self):
+ log.debug(f'spawning {self.nr_concurrent_jobs} to execute more jobs '
+ 'concurrently')
+ for i in range(self.nr_concurrent_jobs):
+ self.spawn_new_thread(i)
+
+ def spawn_more_threads(self):
+ c = len(self.threads)
+ diff = self.nr_concurrent_jobs - c
+ log.debug(f'spawning {diff} threads to execute more jobs concurrently')
+
+ for i in range(c, self.nr_concurrent_jobs):
+ self.spawn_new_thread(i)
+
def set_wakeup_timeout(self):
with self.lock:
# not made configurable on purpose
self.cv.notifyAll()
elif c < self.nr_concurrent_jobs:
# Increase concurrency: create more threads.
- log.debug("creating new threads to job increase")
- for i in range(c, self.nr_concurrent_jobs):
- self.spawn_new_thread(i)
+ self.spawn_more_threads()
self.cv.wait(timeout=self.wakeup_timeout)
def shutdown(self):