On Thu, Nov 17, 2011 at 12:48 AM, Eduardo Oliva <dut...@gmail.com> wrote: > Hello, I have a py script that reads for all "m2ts" video files and convert > them to "mpeg" using ffmpeg with command line. > > What I want to do is: > > I need my script to run 2 separated threads, and then when the first has > finished, starts the next one....but no more than 2 threads. > I know that Semaphores would help with that. > But the problem here is to know when the thread has finished its job, to > release the semaphore and start another thread.
First off, it's better in CPython (the most popular Python) to use multiple processes than multiple threads. That aside, what you're looking at is a pretty common model - a large number of tasks being served by a pool of workers. Have a look at the multiprocessing module, specifically Pool: Version 2: http://docs.python.org/library/multiprocessing.html Version 3: http://docs.python.org/py3k/library/multiprocessing.html Should be fairly straightforward. ChrisA -- http://mail.python.org/mailman/listinfo/python-list