Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.01; 'python.': 0.04; 'concurrent': 0.04; 'instance,': 0.05; 'subject:Python': 0.06; 'threads,': 0.07; 'python': 0.08; 'also:': 0.09; 'concurrency': 0.09; 'content-type:multipart/signed': 0.09; 'executes': 0.09; 'filename:fname piece:signature': 0.09; 'locks': 0.09; 'mapped': 0.09; 'subprocess': 0.09; '(at)': 0.16; '(dot)': 0.16; 'concurrency,': 0.16; 'content-type:application/pgp- signature': 0.16; 'cores': 0.16; 'coroutines': 0.16; 'dangerous,': 0.16; 'filename:fname piece:asc': 0.16; 'filename:fname:signature.asc': 0.16; 'notably': 0.16; "someone's": 0.16; 'threading': 0.16; 'whole,': 0.16; 'wrote:': 0.16; 'language': 0.17; 'exists': 0.18; 'received:209.85.210.174': 0.18; 'received:mail-iy0-f174.google.com': 0.18; 'java,': 0.19; 'programming': 0.20; 'java': 0.21; 'memory': 0.21; 'blog:': 0.21; "doesn't": 0.22; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'runs': 0.23; 'along.': 0.23; 'faster,': 0.23; 'somehow': 0.23; 'pm,': 0.24; 'suspect': 0.24; 'code': 0.25; 'creating': 0.25; 'code.': 0.26; 'separate': 0.28; 'depends': 0.28; 'right.': 0.28; 'pass': 0.29; 'extreme': 0.29; 'cc:addr:gmail.com': 0.30; 'module': 0.30; '(unless': 0.30; 'confused': 0.30; 'hansen': 0.30; 'lock': 0.30; 'really,': 0.30; 'threads': 0.30; 'threads.': 0.30; 'useless': 0.30; 'shared': 0.31; 'third-party': 0.32; 'received:24': 0.32; 'hi,': 0.32; 'actual': 0.32; 'objects': 0.32; 'does': 0.32; 'comment': 0.32; "isn't": 0.33; 'sort': 0.33; 'it.': 0.33; 'actually': 0.33; "can't": 0.33; 'to:addr:python-list': 0.33; 'copying': 0.33; 'operating': 0.33; '...': 0.34; 'but,': 0.34; 'anything': 0.36; 'primary': 0.36; 'doing': 0.36; 'created': 0.36; 'useful': 0.36; 'another': 0.37; 'are.': 0.37; 'mechanisms': 0.37; 'thread': 0.37; 'listed': 0.37; 'reasons': 0.37; 'using': 0.37; 'but': 0.37; 'two': 0.37; 'think': 0.38; 'george': 0.38; 'some': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'easier': 0.38; 'subject:: ': 0.39; 'expensive': 0.39; 'word,': 0.39; 'ways': 0.39; 'goes': 0.39; "there's": 0.39; 'why': 0.39; 'to:addr:python.org': 0.39; 'more': 0.60; 'easily': 0.61; 'your': 0.61; 'address': 0.61; 'kind': 0.61; 'back': 0.62; 'fashion': 0.64; 'ever': 0.65; 'share': 0.65; 'making': 0.67; 'show': 0.67; 'easily.': 0.67; 'power,': 0.67; 'special': 0.67; 'care': 0.71; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.71; 'mail:': 0.73; 'offering': 0.75; 'dispatching': 0.84; 'displayed.': 0.84; 'heck,': 0.84; 'lightweight': 0.84; 'process...': 0.84; 'ps.': 0.84; 'amongst': 0.91; 'mistaken': 0.91; 'url:io': 0.93 Sender: Ixokai Date: Thu, 01 Sep 2011 15:27:32 -0700 From: Stephen Hansen MIME-Version: 1.0 To: python-list@python.org Subject: Re: Threads in Python References: In-Reply-To: X-Enigmail-Version: 1.3.1 OpenPGP: id=555B1FE5; url=http://id.ixokai.io/pub.asc Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigD37D8E8F032C9B27D5BCB9DE" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: me+list/python@ixokai.io 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: 96 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314916069 news.xs4all.nl 2554 [2001:888:2000:d::a6]:39118 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12588 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigD37D8E8F032C9B27D5BCB9DE Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 9/1/11 2:45 PM, George Kovoor wrote: > Hi, > Why doesn't python threads show an associated PID? On spawning python > threads using the threading module I can only see the main thread's pid= on > using top or ps unix command, no subprocesses are displayed. In otherw= ords > top or ps in not aware of any subprocesses created using threading modu= le in > python. > > Whereas in Java , creating threads will result in separate pid , these > subprocesses can be listed using top or ps. Java threads get mapped to = the > cores in the system. I think you're confused about what threads and subprocesses are. They are completely different mechanisms for concurrent code. Threads never show up on top or ps, in any language ... or the language isn't offering threads. I don't know Java, so I can't really comment on it much, but it may be misusing the 'thread' word, but I somehow doubt it. I suspect you're just mistaken about what Java is offering. Threads are separate operating ..er, chains-of-instructions within a single process... Notably with threads, they share the same address space so you can easily share objects amongst threads, without any copying and with no overhead ... Also notably with threads, this can be dangerous, so you often end up wrapping lots of locks around those shared objects and have to take extreme care to make sure nothing goes haywire. Subprocesses are different; they are a whole, separate process with its own address space and no shared memory (unless you go out of your way to do it manually). Heck, each subprocess can have any number of threads. Anything you want to share between them you have to take special care to set up and do -- multiprocessing exists to make this easier and make subprocesses easier to use, like threads are. They're very distinct. Threads are a lot more lightweight and start up a lot faster, but doing multithreaded programming right with any sort of shared objects is really, really, really hard to get right. Some say you can't. But, in Python, only one thread actually ever executes actual Python code at any given time. This does not actually make threading useless as some people claim; if you're making a lot of calls into C-code, for instance, the lock gets released while said C-code runs and other Python code can continue along. Its just not useful if your program is CPU-bound and wants to take advantage of multiple cores. But there's lots of other reasons to go concurrent. But if you do need lots of CPU power, multiprocessing lets you chew up multiple cores and does so /fairly/ easily. Communication between the processes can be expensive depending on the types of objects you need to pass back and forth, but it depends on how you're designing your app. They're just different ways of achieving concurrency, and the two primary ways Python provides. (Greenlets is another, available as a third-party module; Twisted's asynch dispatching isn't really exactly concurrency, but it does a better job then concurrency does for some operations; someone's always working on coroutines in some fashion or another, which is another kind of concurrency.) Lots of different ways to go concurrent, depending on your needs. --=20 Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ --------------enigD37D8E8F032C9B27D5BCB9DE Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.10 (Darwin) iQEcBAEBAgAGBQJOYAbgAAoJEKcbwptVWx/lxA8IAK9jnUKHwhnxsAcN7Za8rBWk OTLrWj68/C7ecJXbzWGHUeLYF2xSt5sq/2Cq9pau5Ac0AZkLzUPh0Uf4zIsLW/qE dptQlHlkIr4E2h2ZnSPxbtMlDG/HWy/5xmmLp5V3JX4oStSvD7qqCKOFEFbRo1vS IR1e7FJ5/YUCpRw7cu4upgTWpb0Pr0TQxbBLjjbR/BdQwBHvSwbNhD+0xT4fg61E D3ku5FN2zCl6R/GAn5R6v08xhe3+OeZ/fmnIIjFLld8KWLQs8EyMPzL3ZpIFAN13 jV8SdQk9hOe6sa6PUyUXmhXriMqw8HZJvHYJBhHKPTLBM2FwguPRPWoyAhfloJM= =W9+E -----END PGP SIGNATURE----- --------------enigD37D8E8F032C9B27D5BCB9DE--