I have a list of Thread objects being passed a BoundedSemaphore. These threads are each started and joined on. As part of the run() process, each acquires a semaphore lock, runs its primary function (a call to an external, rate-limited API), and then releases the lock.
class ThreadProvisioner
def func_a(self):
threads = []
pool = threading.BoundedSemaphore(MAX_THREADS)
for i in range(thread_count):
x = ProcessAgents(pool=pool)
threads.append(x)
thread_output = []
for thread in threads:
thread.start()
thread_output.append(thread.join())
return thread_output
class IndividualThread(threading.Thread):
def __init__(self, pool):
Thread.__init__(self)
self.pool = pool
self.output = {}
def run(self):
self.pool.acquire()
self.func_b()
self.pool.release()
def join(self, *args):
Thread.join(self, *args)
return self.output
def func_b(self):
// do the thing
self.output = output
On execution, it appears to execute entirely sequentially. Rather than allowing up to MAX_THREADS concurrently, only a single thread can be seen running next to MainThread. I've tried searching for similar issues and have seen none. Am I misinterpreting the documentation?