Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #15771

Re: Multiple threads

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'cpython': 0.05; 'python)': 0.05; 'threads,': 0.07; 'finished,': 0.09; 'am,': 0.12; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'semaphores': 0.16; 'subject:threads': 0.16; 'thread.': 0.16; 'workers.': 0.16; 'wrote:': 0.18; 'received:209.85.210.174': 0.18; 'received:mail-iy0-f174.google.com': 0.18; 'convert': 0.19; 'module,': 0.23; 'header:In-Reply-To:1': 0.23; 'starts': 0.23; 'command': 0.24; 'specifically': 0.27; 'script': 0.28; 'message- id:@mail.gmail.com': 0.29; 'problem': 0.29; 'fairly': 0.30; 'separated': 0.30; 'threads.': 0.30; '(the': 0.30; 'url:library': 0.30; 'nov': 0.31; 'version': 0.31; 'thu,': 0.32; 'pretty': 0.32; 'to:addr:python-list': 0.32; '17,': 0.34; 'url:python': 0.35; 'thread': 0.36; 'another': 0.36; 'using': 0.37; 'run': 0.38; 'received:google.com': 0.38; 'hello,': 0.38; 'received:209.85': 0.38; 'url:org': 0.38; 'finished': 0.38; 'url:docs': 0.38; 'should': 0.39; 'help': 0.39; 'tasks': 0.39; "it's": 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; 'release': 0.40; 'files': 0.40; 'received:209': 0.40; 'being': 0.40; 'more': 0.60; '2011': 0.62; 'here': 0.65; '12:48': 0.84; 'eduardo': 0.84; '\xa0but': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=xrjMWljlMQQnQfISV8jQG6wHkjG+h1k+rbR7Lz9d1Nc=; b=LS7w0BftcKV6+dKICItfbodaRA0TyAJZpjK/m0G0H2p53DOBQTAUHKVsNfp3Bklj3V sY8+uQ4drvZ6Vf4tCaLEEg8N0j0gl2ysY83VW8CcTLqki50pCHb8gQk7fhX1O3w83RvC Sw3wByw+tzcULxcGaf38IKkhU4tl7DC+ct+vk=
MIME-Version 1.0
In-Reply-To <31766634.4.1321451296410.JavaMail.geo-discussion-forums@yqcm23>
References <31766634.4.1321451296410.JavaMail.geo-discussion-forums@yqcm23>
Date Thu, 17 Nov 2011 00:55:40 +1100
Subject Re: Multiple threads
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2767.1321451743.27778.python-list@python.org> (permalink)
Lines 24
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1321451743 news.xs4all.nl 6959 [2001:888:2000:d::a6]:41203
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:15771

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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