Am new to python and making some headway with threading
- am doing some music file conversion and want to be able to utilize the multiple cores on my machine (o
If you want to limit the number of parallel threads, use a semaphore:
threadLimiter = threading.BoundedSemaphore(maximumNumberOfThreads)
class EncodeThread(threading.Thread):
def run(self):
threadLimiter.acquire()
try:
<your code here>
finally:
threadLimiter.release()
Start all threads at once. All but maximumNumberOfThreads
will wait in threadLimiter.acquire()
and a waiting thread will only continue once another thread goes through threadLimiter.release()
.