Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #15771
| References | <31766634.4.1321451296410.JavaMail.geo-discussion-forums@yqcm23> |
|---|---|
| Date | 2011-11-17 00:55 +1100 |
| Subject | Re: Multiple threads |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2767.1321451743.27778.python-list@python.org> (permalink) |
On Thu, Nov 17, 2011 at 12:48 AM, Eduardo Oliva <dutche@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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Multiple threads Eduardo Oliva <dutche@gmail.com> - 2011-11-16 05:48 -0800
Re: Multiple threads Chris Angelico <rosuav@gmail.com> - 2011-11-17 00:55 +1100
Re: Multiple threads Henrik Faber <hfaber@invalid.net> - 2011-11-16 15:07 +0100
Re: Multiple threads Christian Heimes <lists@cheimes.de> - 2011-11-16 16:01 +0100
Re: Multiple threads Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-11-16 17:45 +0100
Re: Multiple threads Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-11-16 16:38 -0800
Re: Multiple threads Dave Angel <d@davea.name> - 2011-11-16 12:27 -0500
Re: Multiple threads Michael Hunter <tahoemph@gmail.com> - 2011-11-16 09:55 -0800
Re: Multiple threads Dave Angel <d@davea.name> - 2011-11-16 13:06 -0500
Re: Multiple threads Dave Angel <d@davea.name> - 2011-11-16 13:30 -0500
Re: Multiple threads Miki Tebeka <miki.tebeka@gmail.com> - 2011-11-16 12:50 -0800
csiph-web