Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'completeness': 0.05; '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; 'space).': 0.09; '712': 0.16; '>>so': 0.16; 'cores': 0.16; 'currencies': 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'here).': 0.16; 'jython': 0.16; 'privilege,': 0.16; 'securities,': 0.16; 'sequential': 0.16; 'threading': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'wrote:': 0.16; 'operations.': 0.18; 'appropriate': 0.20; 'java': 0.21; '(like': 0.21; "aren't": 0.21; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'sep': 0.23; 'pm,': 0.24; 'input': 0.24; 'libraries': 0.24; 'stack': 0.24; 'do,': 0.25; 'code': 0.25; 'separate': 0.28; 'thu,': 0.28; 'url:mailman': 0.28; '(even': 0.29; 'message-id:@mail.gmail.com': 0.29; '(and': 0.29; 'module': 0.30; 'asynchronous': 0.30; 'construct': 0.30; 'lock': 0.30; 'threads': 0.30; 'url:library': 0.31; 'does': 0.32; 'to:addr:python-list': 0.33; 'url:listinfo': 0.33; 'however,': 0.34; 'scheduling': 0.34; 'phone:': 0.35; 'running': 0.35; 'supposed': 0.35; 'received:209.85.161': 0.35; 'certain': 0.35; 'url:python': 0.36; 'data.': 0.36; 'doing': 0.36; 'useful': 0.36; 'another': 0.37; 'example,': 0.37; 'accuracy': 0.37; 'thread': 0.37; 'model': 0.37; 'run': 0.37; 'but': 0.37; 'two': 0.37; 'received:google.com': 0.38; 'url:org': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'url:docs': 0.39; 'user': 0.39; 'tasks': 0.39; 'to:addr:python.org': 0.39; 'might': 0.40; 'your': 0.61; 'address': 0.61; 'subject': 0.61; 'waiting': 0.63; 'believe': 0.65; 'information,': 0.65; 'due': 0.66; 'legal': 0.70; 'url:email': 0.74; 'sale': 0.75; 'bank': 0.76; 'investment': 0.77; 'purchase': 0.84; 'machines,': 0.84; 'pc.': 0.96 MIME-Version: 1.0 In-Reply-To: <0604E20B5F6F2F4784C9C8C71C5DD4DD2F165DD74C@EMARC112VS01.exchad.jpmchase.net> References: <0604E20B5F6F2F4784C9C8C71C5DD4DD2F165DD74C@EMARC112VS01.exchad.jpmchase.net> Date: Thu, 1 Sep 2011 18:46:32 -0400 Subject: Re: Python thread From: Benjamin Kaplan To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Junkmail-Status: score=10/49, host=mpv2.tis.cwru.edu X-Junkmail-Signature-Raw: score=unknown, refid=str=0001.0A020207.4E600B49.006B,ss=1,fgs=0, ip=209.85.161.54, so=2010-12-23 16:51:53, dmn=2009-09-10 00:05:08, mode=single engine X-Junkmail-IWF: false 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: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314917202 news.xs4all.nl 2407 [2001:888:2000:d::a6]:34950 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12590 On Thu, Sep 1, 2011 at 6:21 PM, Prasad, Ramit w= rote: >>So what exactly does threading module do, if it doesn't create a subproce= ss. >>Does each thread have its own stack and PC. >>What advantage would a threading module provide over sequential execution= . > > I believe it merely simulates multiple processes through scheduling (like= the CPU). > > >From http://docs.python.org/library/threading.html: CPython implementati= on detail: Due to the Global Interpreter Lock, in CPython only one thread c= an execute Python code at once (even though certain performance-oriented li= braries might overcome this limitation). If you want your application to ma= ke better of use of the computational resources of multi-core machines, you= are advised to use multiprocessing. However, threading is still an appropr= iate model if you want to run multiple I/O-bound tasks simultaneously. > > Ramit 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). > Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology > 712 Main Street | Houston, TX 77002 > work phone: 713 - 216 - 5423 > > > > > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of > securities, accuracy and completeness of information, viruses, > confidentiality, legal privilege, and legal entity disclaimers, > available at http://www.jpmorgan.com/pages/disclosures/email. > -- > http://mail.python.org/mailman/listinfo/python-list >