I have an object with a limited semaphore that ensures that my program does not load more than a certain number of files at a time. Each worker thread receives a semaphore when it starts loading and releases it when it is done.
I have another thread that would like to run code when nothing loads. I need a locking method until the semaphore is fully accessible. How can I do this in Python?
The employee pool seems to be a good solution for this, so you can consider this question and its answers . You can create a pool of workers, send all tasks, a closepool, and then join, to wait until it is over, before transferring the code that you want to run when the files are downloaded.
close
join
. . , , , , - , , ( ); - . , , , .
- . , .
, , , ?
from threading import Semaphore p = Semaphore(5) #Allow 5 times p.acquire() download_file() ... ...
p.acquire() True 5 , . ?