Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.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.051 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; '(even': 0.05; 'advocate': 0.07; 'subject:script': 0.09; 'python': 0.11; 'corrupt': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'mutated': 0.16; 'objects.': 0.16; 'roy': 0.16; 'subject:versus': 0.16; 'wrote:': 0.18; 'meant': 0.20; 'appears': 0.22; 'certainly': 0.24; 'lets': 0.24; "shouldn't": 0.24; 'sorry,': 0.24; 'right.': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'generally': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'easier': 0.31; 'occurs': 0.31; 'purely': 0.31; 'anyone': 0.31; 'file': 0.32; 'running': 0.33; 'fri,': 0.33; "i'd": 0.34; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'doing': 0.36; 'possible': 0.36; 'example,': 0.37; 'two': 0.37; 'level': 0.37; 'awesome': 0.38; 'needed': 0.38; 'to:addr:python-list': 0.38; 'anything': 0.39; 'though,': 0.39; 'to:addr:python.org': 0.39; 'lower': 0.61; 'range': 0.61; 'simple': 0.61; "you're": 0.61; 'kind': 0.63; 'soon': 0.63; 'different': 0.65; 'smith': 0.68; 'guaranteed': 0.75; 'protects': 0.84; 'eliminates': 0.91; 'political': 0.97; '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:date:message-id:subject:from:to :content-type; bh=XaOQbSRgWb8t8ehLqR3hctU5LseC1rQE9C5p+KdrUag=; b=XgInbgeHH3hhGxKnR9UVovozar+QxAwGr69g3d2pxwH/LzWTirAGcNPEz3GHMsk+5H jxHCMHsq5AUcfbi2f+quBcEQM1+d98pK0qYca6r1wlU7gZS/kfekHPqFx7z3X5nIfJbR oAFZlb7/AltvXev/+BRmnBzeYgmQVihBRQE1PDldbu84SpDR7wtjQPe8r04fJSGlEZ8W 7Cx8dJOQA0mbuEOhA4Y2HrfOuIMxtDkLStUF880ZdarsqPrJV++1OlqponPdrrafyIJ3 8kvKdqdKApw1fYwroC6vBZDuX4b4lCpXuiYLyReP/w7QVrG/DUNmBE6W+XxoQUUPgQBQ qx5g== MIME-Version: 1.0 X-Received: by 10.66.154.1 with SMTP id vk1mr11157908pab.85.1380825385953; Thu, 03 Oct 2013 11:36:25 -0700 (PDT) In-Reply-To: References: Date: Fri, 4 Oct 2013 04:36:25 +1000 Subject: Re: Multiple scripts versus single multi-threaded script From: Chris Angelico To: python-list@python.org 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1380825390 news.xs4all.nl 15891 [2001:888:2000:d::a6]:41606 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:55437 On Fri, Oct 4, 2013 at 4:28 AM, Roy Smith wrote: > Well, the GIL certainly eliminates a whole range of problems, but it's > still possible to write code that deadlocks. All that's really needed > is for two threads to try to acquire the same two resources, in > different orders. I'm running the following code right now. It appears > to be doing a pretty good imitation of a deadlock. Any similarity to > current political events is purely intentional. Right. Sorry, I meant that the GIL protects you from all that happening in the lower level code (even lower than the Senate, here), but yes, you can get deadlocks as soon as you acquire locks. That's nothing to do with threading, you can have the same issues with databases, file systems, or anything else that lets you lock something. It's a LOT easier to deal with deadlocks or data corruption that occurs in pure Python code than in C, since Python has awesome introspection facilities... and you're guaranteed that corrupt data is still valid Python objects. As to your corrupt data example, though, I'd advocate a very simple system of object ownership: as soon as the object has been put on the queue, it's "owned" by the recipient and shouldn't be mutated by anyone else. That kind of system generally isn't hard to maintain. ChrisA