Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1a.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '(at': 0.04; 'output': 0.05; '(so': 0.07; 'see.': 0.07; 'earliest': 0.09; 'second.': 0.09; 'slow.': 0.09; 'yeah,': 0.09; 'cc:addr:python-list': 0.11; '255': 0.16; 'bitwise': 0.16; 'block.': 0.16; 'blocking': 0.16; 'division.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterated': 0.16; 'sense:': 0.16; 'two,': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'replacing': 0.19; 'thu,': 0.19; 'programming': 0.22; '(in': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'certainly': 0.24; 'days,': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'logging': 0.26; 'least': 0.26; 'header:In-Reply- To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; 'clock': 0.31; 'faster,': 0.31; 'screen': 0.34; "i'd": 0.34; "can't": 0.35; 'something': 0.35; 'case,': 0.35; 'operations': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'right?': 0.36; "i'll": 0.36; 'should': 0.36; 'being': 0.38; 'remote': 0.38; 'rather': 0.38; 'enough': 0.39; 'either': 0.39; 'how': 0.40; 'even': 0.60; 'most': 0.60; "you're": 0.61; 'back': 0.62; 'show': 0.63; 'maximum': 0.63; 'more': 0.64; 'overall': 0.69; 'obvious': 0.74; 'power': 0.76; 'heh.': 0.84; "it'd": 0.84; 'slowed': 0.84; 'to:none': 0.92 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; bh=Og72VISwvSWN6lqfdKPMeMgPZ8Fk7YpPv/Z5frQdywA=; b=zYjsC+J0UQhS2u1HLgg+mr1cfldFjATzXuT7CFkdSNCdizW64FMnD5GTIH7ou/7AFU x/36chWb+dMt4NJNGjrJ1eG7teAGUvOIuEzYHvrhxWYghUZkmN4DfknIgnyrtkq5iucf e759NgOvncpQ8n040WwzpVbcycevFE/YfH2eLUCBkHcR+yzCenAXJIYU59djcl1KWbhv KX+sCABo31iDtKf7sFarqjHqJ4tuweFUFfkBz8p9TP37upsp+zxTmEhN7+PPPm9ZS+Rs 4XhgrW6jWgDtjp8LDSOP5OE9WTYSBtQEhjaOl3zQffstb5luYU/C1iPArd9Az3pfNo2h ZpAA== MIME-Version: 1.0 X-Received: by 10.69.25.69 with SMTP id io5mr16307688pbd.22.1397091915376; Wed, 09 Apr 2014 18:05:15 -0700 (PDT) In-Reply-To: References: <87d2gt4td2.fsf@elektro.pacujo.net> <7xha651yx2.fsf@ruckus.brouhaha.com> <877g70wg8p.fsf@elektro.pacujo.net> Date: Thu, 10 Apr 2014 11:05:15 +1000 Subject: Re: threading From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 58 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1397091924 news.xs4all.nl 2887 [2001:888:2000:d::a6]:47623 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69996 On Thu, Apr 10, 2014 at 9:44 AM, Dennis Lee Bieber wrote: > On Wed, 9 Apr 2014 23:47:04 +1000, Chris Angelico > declaimed the following: > >>won't block. You might think "Duh, how can printing to the screen >>block?!?", but if your program's output is being piped into something >>else, it most certainly can :) If that were writing to a remote > > Heck, even if it isn't blocking per se, it may still be enough to slow > down the whole system (over the past year I've had to characterize through > put on some systems -- and the console logging of "exceptions"* slowed the > overall data rate significantly) Oh yes, definitely. Console output can be *slow*. Back in my earliest programming days, I'd often have a program that iterated over sub-jobs from either 0 or 1 up to some unknown top (so I can't show a percent-done), and the obvious thing to do is (rewritten in Python): i = 0 while stuff_to_do(): i += 1 print(i, end="\r") do_more_stuff() print(i) Hmm, that's really slow. I know! I'll speed this up by printing out only once a second. That should be way faster, right? Let's see. i = time_printed = 0 while stuff_to_do(): i += 1 if int(time.time()) != time_printed: print(i, end="\r") time_printed = int(time.time()) do_more_stuff() print(i) And that made it... waaaay slower. Turns out clock querying (at least on those systems) is pretty slow too, even more so than console output. Of course, what we ended up settling on was something like this, which *does* make sense: i = 0 while stuff_to_do(): i += 1 if i & 255 == 0: print(i, end="\r") do_more_stuff() print(i) replacing 255 with any number one less than a power of two, so it'd print out every however-many-th (in this case, every 256th), using bitwise operations rather than division. But yeah, console output isn't something you want when you're going for maximum throughput. Heh. ChrisA