I have a bounded semaphore object that ensures my program doesn’t download more than a certain number of files at a time. Each worker thread acquires the semaphore when it starts downloading and releases it when done.
I have another thread that would like to run code when nothing is being downloaded. I would like a method for locking until the semaphore is completely available. How can I do this in Python?
A pool of workers sounds like a good solution for this, so you might consider this question and its answers. You can create the pool of workers, submit all the jobs,
closethe pool, and thenjoinit to wait for things to finish before handing off to the code you want to run when the files are done downloading.