Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!txtfeed1.tudelft.nl!tudelft.nl!txtfeed2.tudelft.nl!amsnews11.chello.com!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'threads,': 0.07; 'python': 0.08; 'description,': 0.09; 'finished,': 0.09; 'many)': 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; 'spawn': 0.09; 'great.': 0.15; 'bieber': 0.16; 'declaimed': 0.16; 'email addr:ix.netcom.com': 0.16; 'email name:wlfraed': 0.16; 'from:addr:ix.netcom.com': 0.16; 'from:addr:wlfraed': 0.16; 'from:name:dennis lee bieber': 0.16; 'rachel': 0.16; 'received:66.245': 0.16; 'received:dsl.mindspring.com': 0.16; 'received:wlfraed': 0.16; 'semaphores': 0.16; 'subject:threads': 0.16; 'subprocess,': 0.16; 'thread.': 0.16; 'url:netcom': 0.16; 'url:wlfraed': 0.16; 'wulfraed': 0.16; 'wed,': 0.17; 'simpler': 0.18; 'convert': 0.19; 'trying': 0.21; 'url:home': 0.21; '(or': 0.22; 'runs': 0.23; '+0100,': 0.23; 'all:': 0.23; 'pair': 0.23; 'starts': 0.23; 'command': 0.24; "i'm": 0.26; 'work.': 0.27; 'lee': 0.28; 'script': 0.28; 'problem': 0.29; 'processes.': 0.30; 'queue': 0.30; 'separated': 0.30; 'threads': 0.30; 'threads.': 0.30; 'worker': 0.30; 'nov': 0.31; 'shared': 0.31; 'actual': 0.32; 'does': 0.32; 'to:addr:python-list': 0.32; 'it.': 0.33; 'done': 0.33; 'header:X-Complaints-To:1': 0.33; 'external': 0.35; 'charset :us-ascii': 0.36; '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; 'feed': 0.38; 'finished': 0.38; 'help': 0.39; 'why': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; 'release': 0.40; 'data': 0.40; 'files': 0.40; 'more': 0.60; '2011': 0.62; 'here': 0.65; 'dennis': 0.77; '14:48': 0.84; 'eduardo': 0.84; 'schrieb': 0.84; 'wait,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Multiple threads Date: Wed, 16 Nov 2011 16:38:09 -0800 Organization: > Bestiaria Support Staff < References: <31766634.4.1321451296410.JavaMail.geo-discussion-forums@yqcm23> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: user-11fb5l5.dsl.mindspring.com X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1321490302 news.xs4all.nl 6846 [2001:888:2000:d::a6]:40490 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15795 On Wed, 16 Nov 2011 17:45:29 +0100, Thomas Rachel declaimed the following in gmane.comp.python.general: > 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. > > > > Any help would be great. > > I'm not sure if you need threads at all: if you launch a process with > subprocess, it runs and you only would have to wait() for it. The same > can be done with two processes. > In the larger problem description, though, it is mentioned that the actual conversion is done by spawning an "ffmpeg" command... So why run a Python process whose only activity is to spawn a process that does the real work. Using a pair (or however many) worker threads which feed off a shared Queue for the files to convert, and then spawn the ffmpeg process(es) and wait, is likely simpler than trying to feed data to external processes. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/