Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed20.multikabel.net!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'threads,': 0.07; 'python': 0.08; 'consume': 0.09; 'finished,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'semaphores': 0.16; 'subject:threads': 0.16; 'thread.': 0.16; 'convert': 0.19; 'suggest': 0.20; 'header:In-Reply-To:1': 0.23; 'starts': 0.23; 'command': 0.24; 'script': 0.28; 'problem': 0.29; 'queue': 0.30; 'separated': 0.30; 'threads': 0.30; 'threads.': 0.30; 'worker': 0.30; 'url:library': 0.30; 'to:addr:python-list': 0.32; 'header :User-Agent:1': 0.33; 'header:X-Complaints-To:1': 0.33; 'url:python': 0.35; 'thread': 0.36; 'another': 0.36; 'but': 0.37; 'two': 0.37; 'using': 0.37; 'received:org': 0.37; 'run': 0.38; 'hello,': 0.38; 'url:org': 0.38; 'finished': 0.38; 'url:docs': 0.38; 'help': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; 'release': 0.40; 'files': 0.40; 'more': 0.60; 'here': 0.65; '(one': 0.73; 'eduardo': 0.84; 'schrieb': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Christian Heimes Subject: Re: Multiple threads Date: Wed, 16 Nov 2011 16:01:15 +0100 References: <31766634.4.1321451296410.JavaMail.geo-discussion-forums@yqcm23> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: smtp.semantics.de User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 In-Reply-To: <31766634.4.1321451296410.JavaMail.geo-discussion-forums@yqcm23> X-Enigmail-Version: 1.4a1pre OpenPGP: id=AD16AB1B; url=http://cheimes.de/heimes.asc X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1321455690 news.xs4all.nl 6951 [2001:888:2000:d::a6]:40252 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15776 Am 16.11.2011 14:48, schrieb Eduardo Oliva: > 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. I suggest a slight different approach: use a queue [1] and create two worker threads that consume the queue. You don't need multiprocessing because you are already using multiple processes here (one Python and two ffmpeg processes). Christian [1] http://docs.python.org/library/queue.html