Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'interpreter': 0.05; 'subject:Python': 0.06; 'concurrently': 0.07; 'permitted': 0.07; 'run,': 0.09; 'python': 0.11; 'thread': 0.14; '1:08': 0.16; 'concurrency': 0.16; 'criterion.': 0.16; 'machine?': 0.16; 'threads,': 0.16; 'extensions': 0.16; 'wrote:': 0.18; '(where': 0.19; 'thu,': 0.19; 'python?': 0.22; 'closely': 0.24; 'module,': 0.24; 'guys': 0.24; 'looks': 0.24; 'switch': 0.26; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; 'generally': 0.29; 'dec': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'allows': 0.31; 'option': 0.32; 'run': 0.32; '(e.g.': 0.33; 'could': 0.34; 'message.': 0.35; 'advice': 0.35; 'objects': 0.35; 'operations': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'two': 0.37; 'list': 0.37; 'being': 0.38; 'tasks': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; '12,': 0.39; 'expensive': 0.39; 'to:addr:python.org': 0.39; 'release': 0.40; 'how': 0.40; 'experts': 0.60; 'hope': 0.61; 'no.': 0.61; 'more': 0.64; 'between': 0.67; 'subject': 0.69; 'protects': 0.84; 'browsing': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=zFDwxdTLL5uqZWdNCF2e9rkDANoySZmAys1ZluBMGQ0=; b=j6GtrqYc4swZt/kNk71jc9mUU7AKUDi4a6q+g2z0OApysU1c2dOLv17mx9oDiElMu0 4ua2LXvCQvtA9iaHMj3CDW5aWDVEDmT2QP1iz8EWkfZvodmr6w4iUxpg0KBqGcMey7BJ nY8KzFOjVKw+Az9Gj1cuTnAMuQcMV8Fr57JgvEnogqcIuuE2lLb2lSzWvY0V+qmvm8bq fCfOWkUTs7DUqXI5qGygYZ3v/mg9/g+YEap/TAPHzgEDHEKNW6v3eymhxfUp8ibMQ4Am WugHfW83hv1QJ16ACZI9VZVY++TDzaL+Xe6dgrq5eVP81M1doJsSFHrbmAt1oe17TqSA lRkg== X-Received: by 10.52.230.102 with SMTP id sx6mr2374565vdc.15.1386837751955; Thu, 12 Dec 2013 00:42:31 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Thu, 12 Dec 2013 01:41:51 -0700 Subject: Re: Threading In Python To: Python Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1386837754 news.xs4all.nl 2839 [2001:888:2000:d::a6]:60670 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:61685 On Thu, Dec 12, 2013 at 1:08 AM, marcinmltd wrote: > Adding subject to the message. > Hello, > > I'm big fan of multiprocessing module, but recently I started looking at > threading in Python more closely and got couple of questions I hope You can > help me with: > > 1. When I run two or more threads in my python process are they really run > concurrently on mulicore machine? No. The GIL allows the Python interpreter to run in only thread at a time. > 2. Browsing through documentation it looks like python interpreter protects > its sensitive states by using GIL. Can you guys list situations when this > happens? Any time Python code is being run, the GIL is held. C extensions have the option to release the GIL for long-running operations (e.g. waiting on a network socket), but they are not permitted to work with Python objects while the GIL is released. > 2. What would be general advice from python experts on when to use threadng > and when switch to multliprocessing in python? Is the decision still > influenced by how often we need to comunicate between the tasks as it's in > C\C++? Generally speaking, use threading for programs that are IO-bound (where there would be little concurrency anyway) and multiprocessing for programs that are CPU-bound. Communication between processes is more expensive than communication between threads, so that could be an important criterion.