Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.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; 'subject:error': 0.03; 'else:': 0.03; 'explicit': 0.07; 'socket': 0.07; 'bytes.': 0.09; 'currently,': 0.09; 'friday,': 0.09; 'logic': 0.09; 'subject:using': 0.09; 'yeah,': 0.09; 'api': 0.11; 'cc:addr :python-list': 0.11; 'python': 0.11; 'thread': 0.14; 'windows': 0.15; 'charset': 0.16; 'contexts,': 0.16; 'foot': 0.16; 'fork': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ignored,': 0.16; 'messy': 0.16; 'reproduce': 0.16; 'runs,': 0.16; 'shooting': 0.16; 'sorts': 0.16; 'subject:distribution': 0.16; 'trace.': 0.16; 'underlying': 0.16; 'unicode.': 0.16; 'unsafe': 0.16; 'elements': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'pointed': 0.19; 'stack': 0.19; 'later': 0.20; 'separate': 0.22; 'tests': 0.22; 'cc:addr:python.org': 0.22; 'error': 0.23; 'bytes': 0.24; 'subject:python.org': 0.24; 'unicode': 0.24; 'mon,': 0.24; "haven't": 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'switch': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'errors': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; '(maybe': 0.31; 'libraries': 0.31; 'pipe': 0.31; 'produces': 0.31; "they'll": 0.31; 'there.': 0.32; 'stuff': 0.32; 'run': 0.32; 'text': 0.33; 'actively': 0.33; 'becomes': 0.33; 'entirely': 0.33; 'guess': 0.33; "i'd": 0.34; "can't": 0.35; 'connection': 0.35; 'problem.': 0.35; 'something': 0.35; 'good.': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'are,': 0.36; 'done': 0.36; 'next': 0.36; 'possible': 0.36; 'should': 0.36; 'error.': 0.37; 'two': 0.37; 'even': 0.60; 'read': 0.60; 'applicable': 0.60; 'liked': 0.60; 'problems.': 0.60; 'most': 0.60; 'break': 0.61; 'new': 0.61; 'simply': 0.61; "you're": 0.61; 'first': 0.61; 'save': 0.62; "you'll": 0.62; 'act': 0.63; 'real': 0.63; 'different': 0.65; 'management': 0.65; 'facilities': 0.69; 'guaranteed': 0.75; 'yourself': 0.78; 'potentially': 0.81; 'fails,': 0.84; 'hassle': 0.84; 'results,': 0.84; 'risking': 0.84; 'str.': 0.91; 'try.': 0.91; 'to:none': 0.92; 'connection,': 0.95 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:cc :content-type:content-transfer-encoding; bh=9flWPD/FszFy5ClB5iEDhsLyFrF8Hk1HIgsLIlj6hik=; b=hfzh5BY3cKykzrtFcwwaBd60Fzg8lNJZ6EqqNH5Tpxvigd3hNTQoEP2d6XLRurHS2U AD03bq4M6qQlNYUrFeHrC0kBf6TinruBCJsJTy3iejfddrQcDuGsjlaAN6P1opaVFqL/ pFlN+b1l7z0J/Dhn7IR6m694qwyyM3EMYkQ/Z0UFcBoezh2Nn0NpOP44c77+iTG+0H76 TYsZaclXBusFy2TeCXWcl8F/peI/i0XRtBwHosoGYrycr5lZinfG6dAJIjZgRGsSdHy1 eyi+f2Wyk0SrKehm43Js1NvMMymByxDbEnc9SARNGLpaUFxxzZZEyCer7NUzcAs+pymJ Iplg== MIME-Version: 1.0 X-Received: by 10.58.107.65 with SMTP id ha1mr18492632veb.1.1398609218874; Sun, 27 Apr 2014 07:33:38 -0700 (PDT) In-Reply-To: <675725e3-38d2-4d81-bf64-f6d903d4a684@googlegroups.com> References: <675725e3-38d2-4d81-bf64-f6d903d4a684@googlegroups.com> Date: Mon, 28 Apr 2014 00:33:38 +1000 Subject: Re: MacOS 10.9.2: threading error using python.org 2.7.6 distribution From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1398609228 news.xs4all.nl 2943 [2001:888:2000:d::a6]:39046 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:70654 On Mon, Apr 28, 2014 at 12:16 AM, Matthew Pounsett wrote: > On Friday, 25 April 2014 10:05:03 UTC-4, Chris Angelico wrote: >> First culprit I'd look at is the mixing of subprocess and threading. >> It's entirely possible that something goes messy when you fork from a >> thread. > > I liked the theory, but I've run some tests and can't reproduce the error= that way. I'm using all the elements in my test code that the real code r= uns, and I can't get the same error. Even when I deliberately break things= I'm getting a proper exception with stack trace. > In most contexts, "thread unsafe" simply means that you can't use the same facilities simultaneously from two threads (eg a lot of database connection libraries are thread unsafe with regard to a single connection, as they'll simply write to a pipe or socket and then read a response from it). But processes and threads are, on many systems, linked. Just the act of spinning off a new thread and then forking can potentially cause problems. Those are the exact sorts of issues that you'll see when you switch OSes, as it's the underlying thread/process model that's significant. (Particularly of note is that Windows is *very* different from Unix-based systems, in that subprocess management is not done by forking. But not applicable here.) You may want to have a look at subprocess32, which Ned pointed out. I haven't checked, but I would guess that its API is identical to subprocess's, so it should be a drop-in replacement ("import subprocess32 as subprocess"). If that produces the exact same results, then it's (probably) not thread-safety that's the problem. >> Separately: You're attempting a very messy charset decode there. You >> attempt to decode as UTF-8, errors ignored, and if that fails, you log >> an error... and continue on with the original bytes. You're risking >> shooting yourself in the foot there; I would recommend you have an >> explicit fall-back (maybe re-decode as Latin-1??), so the next code is >> guaranteed to be working with Unicode. Currently, it might get a >> unicode or a str. > > Yeah, that was a logic error on my part that I hadn't got around to notic= ing, since I'd been concentrating on the stuff that was actively breaking. = That should have been in an else: block on the end of the try. > Ah good. Keeping bytes versus text separate is something that becomes particularly important in Python 3, so I always like to encourage people to get them straight even in Py2. It'll save you some hassle later on. ChrisA