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


Groups > comp.lang.python > #15780

Re: Multiple threads

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!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python,': 0.01; 'languages,': 0.03; 'cpython': 0.05; 'python)': 0.05; 'space.': 0.07; 'threads,': 0.07; 'python': 0.08; 'variables.': 0.09; '16,': 0.15; 'cc:addr:python-list': 0.15; 'chris,': 0.16; 'differently,': 0.16; 'downside': 0.16; 'received:192.168.1.104': 0.16; 'subject:threads': 0.16; 'thread.': 0.16; 'trash': 0.16; 'wed,': 0.17; 'cheers,': 0.18; 'wrote:': 0.18; 'example.': 0.18; 'exists': 0.18; 'please?': 0.18; 'cc:no real name:2**0': 0.21; 'process,': 0.21; 'default,': 0.23; 'header:In-Reply-To:1': 0.23; 'code': 0.25; 'work,': 0.26; "i'm": 0.26; 'separate': 0.28; 'bit': 0.28; 'made.': 0.28; 'cc:addr:python.org': 0.29; 'problem': 0.29; 'cc:addr:gmail.com': 0.30; 'generally': 0.30; 'confused': 0.30; 'letting': 0.30; 'optimal': 0.30; 'os,': 0.30; 'processes.': 0.30; 'separately': 0.30; 'tasks,': 0.30; 'threads': 0.30; 'threads.': 0.30; '(the': 0.30; 'chris': 0.30; 'ago': 0.30; 'nov': 0.31; 'pm,': 0.31; 'suit': 0.32; 'does': 0.32; 'operating': 0.33; 'decide': 0.33; 'header:User-Agent:1': 0.33; 'handled': 0.34; 'another.': 0.34; 'scheduling': 0.34; 'problem.': 0.36; 'file': 0.36; 'cc:2**1': 0.36; 'thread': 0.36; 'variables': 0.36; 'another': 0.36; 'doing': 0.37; 'but': 0.37; 'two': 0.37; 'using': 0.37; 'run': 0.38; 'some': 0.38; 'received:192': 0.38; 'either': 0.39; "couldn't": 0.39; 'tasks': 0.39; "it's": 0.39; 'subject:: ': 0.39; 'might': 0.39; 'extremely': 0.40; 'data': 0.40; 'really': 0.40; 'more': 0.60; 'within': 0.60; 'your': 0.61; 'address': 0.61; 'manager,': 0.62; '2011': 0.62; 'share': 0.66; 'processes,': 0.67; 'header:Reply-To:1': 0.70; 'reply-to:no real name:2**0': 0.71; 'concept': 0.74; 'elaborate': 0.84; 'overhead.': 0.84; 'pain': 0.84
Date Wed, 16 Nov 2011 12:27:52 -0500
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15
MIME-Version 1.0
To Jack Keegan <whatsjacksemail@gmail.com>
Subject Re: Multiple threads
References <31766634.4.1321451296410.JavaMail.geo-discussion-forums@yqcm23> <CAPTjJmoAWni4-wyKB4HgAJ5KvTbz42_BC3f22MOnugUmmXzVtA@mail.gmail.com> <CAAdqOWF=irJXFO2q2+o8jpM09GMLf8N+NTNGTOtMhwKgtG6jag@mail.gmail.com>
In-Reply-To <CAAdqOWF=irJXFO2q2+o8jpM09GMLf8N+NTNGTOtMhwKgtG6jag@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:FQf9F+hcxw8LB9jhQUK0gutAlsIK66BotQsePNVxq2e 6KbvMLlpwckv9SW4Zr4Q1F125jwwqSVct4ZoDVorOhuh004QmJ NBPfF/aPFRRbFZ7O8rHEW+nFRnwjdrHuFVdja3Glp/NSL+xr0J PJm1EBv8OzpcCdnsn8uUJm/wvNuxF5lTiAJZMQciO97ZXAyx1/ YASKzY+xr8PJckN6PTfQMqoLhNMoimUDMJTlnC5qA6y/T5HzYD H2rlxuB5niK0rbuCfTlj8PEUmPQ/Q/9UyUGVkLhyHymSZ31zAp wcN8zyU7Nd1L24eLyuiArnNMGMqJLOzx8B0IIj6awfCAZWsUA= =
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To d@davea.name
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.2775.1321464507.27778.python-list@python.org> (permalink)
Lines 48
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1321464507 news.xs4all.nl 6920 [2001:888:2000:d::a6]:55768
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:15780

Show key headers only | View raw


On 11/16/2011 12:00 PM, Jack Keegan wrote:
> Hi Chris,
>
> On Wed, Nov 16, 2011 at 1:55 PM, Chris Angelico<rosuav@gmail.com>  wrote:
>
>> First off, it's better in CPython (the most popular Python) to use
>> multiple processes than multiple threads.
>
> I had been looking into treads and process/subprocess myself a while ago
> and couldn't decide which would suit what I needed to do best. I'm still
> very confused about the whole thing. Can you elaborate on the above a bit
> please?
>
> Cheers,
>
> Jack
Threads and processes are a concept that exists in your operating 
system, and Python can use either of them to advantage, depending on the 
problem.  Note that different OS also handle them differently, so code 
that's optimal on one system might not be as optimal on another.  Still, 
some generalities can be made.

Each process is a separate program, with its own address space and its 
own file handles, etc.  You can examine them separately with task 
manager, for example.  If you launch multiple processes, they might not 
even all have to be python, so if one problem can be handled by an 
existing program, just run it as a separate process.   Processes are 
generally very protected from each other, and the OS is generally better 
at scheduling them than it is at scheduling threads within a single 
process.  If you have multiple cores, the processes can really run 
simultaneously, frequently with very small overhead.  The downside is 
that you cannot share variables between processes without extra work, so 
if the two tasks are very interdependent, it's more of a pain to use 
separate processes.

Within one process, you can have multiple threads.  On some OS, and in 
some languages, this can be extremely efficient.  Some programs launch 
hundreds of threads, and use them to advantage.  By default, it's easy 
to share data between threads, since they're in the same address space.  
But the downsides are 1) it's very easy to trash another thread by 
walking on its variables.  2) Python does a lousy job of letting threads 
work independently.  For CPU-bound tasks, using separate threads is 
likely to be slower than just doing it all in one thread.

-- 

DaveA

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