Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder5.xlned.com!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'cpython': 0.05; 'subject:Python': 0.06; 'concurrently': 0.07; 'interpreter': 0.07; 'python': 0.08; 'concurrency': 0.09; 'ironpython': 0.09; 'prevents': 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; 'space).': 0.09; 'url:linux': 0.09; 'benjamin': 0.16; 'cores': 0.16; 'here).': 0.16; 'jython': 0.16; 'op.': 0.16; 'pthread': 0.16; 'thread.': 0.16; 'threading': 0.16; 'linux': 0.17; 'operations.': 0.18; 'java': 0.21; "aren't": 0.21; 'process,': 0.21; 'header:In- Reply-To:1': 0.22; 'input': 0.24; 'code': 0.25; 'separate': 0.28; '(and': 0.29; 'asynchronous': 0.30; 'confusion': 0.30; 'construct': 0.30; 'lock': 0.30; 'processes.': 0.30; 'table.': 0.30; 'threads': 0.30; 'list': 0.32; 'to:addr:python-list': 0.33; 'header:User-Agent:1': 0.34; 'header:X-Complaints-To:1': 0.35; 'entry': 0.35; 'running': 0.35; 'supposed': 0.35; 'explain': 0.36; 'data.': 0.36; 'doing': 0.36; 'created': 0.36; 'useful': 0.36; 'another': 0.37; 'example,': 0.37; 'thread': 0.37; 'run': 0.37; 'but': 0.37; 'two': 0.37; 'received:org': 0.38; 'subject:: ': 0.39; 'header:Mime-Version:1': 0.39; 'user': 0.39; 'to:addr:python.org': 0.39; 'url:net': 0.60; 'address': 0.61; 'waiting': 0.63; 'show': 0.67; 'schrieb': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Christian Heimes Subject: Re: Python thread Date: Fri, 02 Sep 2011 01:09:51 +0200 References: <0604E20B5F6F2F4784C9C8C71C5DD4DD2F165DD74C@EMARC112VS01.exchad.jpmchase.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: f049130068.adsl.alicedsl.de User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110617 Lightning/1.0b2.102ipre2 Thunderbird/3.1.11 In-Reply-To: X-Enigmail-Version: 1.1.2 OpenPGP: id=AD16AB1B; url=http://cheimes.de/heimes.asc 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314918607 news.xs4all.nl 2429 [2001:888:2000:d::a6]:60814 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12593 Am 02.09.2011 00:46, schrieb Benjamin Kaplan: > Threading is an OS-level construct to allow concurrency within a > single process (and address space). Threads are never supposed to be > separate processes (they aren't at the C-level, so I don't know what > Java is doing here). CPython code has a global interpreter lock which > prevents two threads from running Python code at the same time, but > they're still useful for asynchronous operations. For example, one > thread can be waiting for user input while another thread continues to > process data. Other Python implementations such as Jython and > IronPython don't have a global interpreter lock so threads can run > concurrently (and on different cores in a multi-core machine). On Linux threading is implemented with multiple processes. A Linux pthread is a clone of the process created with the clone(2) syscall. [1] Each thread has a PID and an entry in the kernel's process table. Tools like htop can show user land threads as different processes. This may explain the confusion of the OP. He may have seen multiple Java threads as different processes. psutil can list all threads with PIDs. The getpid(2) syscall returns always the PID of the main process, gettid (only available through syscall(SYS_gettid)) returns the PID of the current thread. Christian [1] http://linux.die.net/man/2/clone