Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1a.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'environments': 0.07; 'subject:would': 0.07; 'assuming': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'gui': 0.12; 'better:': 0.16; 'fancy': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'instead:': 0.16; 'loop.': 0.16; 'reproduce': 0.16; 'simple.': 0.16; 'subject: \n ': 0.16; 'thread,': 0.16; 'threads,': 0.16; 'time.time()': 0.16; 'true:': 0.16; 'way;': 0.16; 'skip:= 10': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'app': 0.19; 'thu,': 0.19; 'later': 0.20; 'code,': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'features,': 0.24; 'issue,': 0.24; 'simpler': 0.24; 'cc:2**0': 0.24; 'right.': 0.26; 'this:': 0.26; 'header:In-Reply- To:1': 0.27; 'on,': 0.29; 'am,': 0.29; 'subject:) ': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; '(maybe': 0.31; 'subject:what': 0.31; 'probably': 0.32; 'run': 0.32; 'framework': 0.33; 'minimal': 0.33; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'subject:?': 0.36; 'effort': 0.37; 'two': 0.37; 'easily': 0.37; 'little': 0.38; 'recent': 0.39; 'explain': 0.39; 'environment.': 0.39; 'around.': 0.60; 'impact': 0.61; 'skip:t 30': 0.61; 'mentioned': 0.61; 'skip:* 10': 0.61; 'simple': 0.61; "you're": 0.61; 'afraid': 0.65; 'here': 0.66; 'sample': 0.67; 'guts': 0.84; 'subject:much': 0.91; '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=odyOGDTMAOMfZvbb01e9ktX276KpBnn1tm3shlNZx2Q=; b=Rbw1IqUoaqh8dRZOgQ/K+k2TZRGdC+QsjivdZTHZoGIBzoypkt6hw98+RTRt2lkncm MKHYXkkHg7N8ioDwduklpFITVQ9Zg30Cfl3+wDC88gdqpGwEsYxaDyK2uuNtaYj9Aw/J vXBfPz0csKvH1mDLLsVJx2UWyBW+Tdd8TLR1a4DWQ0LiLusaX+VFB3uCOohTlkNnBhIM v5pvQ78Ksj1BU1TS6m9WfBHHGnP2cm8OF/X8LnR7HGa4XuWMHdJcSDvXAt9ZnArP3ZSN Wk4AkK3cMhSV1Cj7g4b4fMpxKBKkHfdQDdzSL6DkRNJmReBCHNshqjkJ4J6JdyQZXspG KwZg== MIME-Version: 1.0 X-Received: by 10.52.64.225 with SMTP id r1mr649800vds.30.1403134694359; Wed, 18 Jun 2014 16:38:14 -0700 (PDT) In-Reply-To: <4d7c474a-b88e-4dea-b74c-ed34f4969310@googlegroups.com> References: <713f4189-5ffe-492d-9c7d-447bb4b4928a@googlegroups.com> <4d7c474a-b88e-4dea-b74c-ed34f4969310@googlegroups.com> Date: Thu, 19 Jun 2014 09:38:14 +1000 Subject: Re: Under what kind of situation, time.sleep(n) would sleep much longer than n seconds? 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: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1403134697 news.xs4all.nl 2871 [2001:888:2000:d::a6]:47549 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73388 On Thu, Jun 19, 2014 at 1:24 AM, crow wrote: > Here is a sample code that can reproduce this issue, you need to wait for it to run for a while. > ****************** > import time > import threading > import wx > > def sleep(): > while True: > t = time.time() > time.sleep(1) > print "Actually sleep:", time.time() - t > > > t1 = threading.Thread(target=sleep) > t1.start() > > app =wx.App(False) > frame = wx.Frame(None, title="test") > frame.Show(True) > app.MainLoop() Okay... you're adding two important complications that you hadn't mentioned originally: Python threads, and a GUI main loop. I could explain the impact that each of these might have on time.sleep(), but given your other recent questions, I'm going to say this instead: Don't be afraid of the console. When you write Python code, start by assuming that it will be run in the standard "glass teletype" console. One thread, simple imperative code, no GUI event loop, keep it simple. Later on, you can add fancy features, but start by getting your main program code working in a simpler environment. In a lot of cases, a simple single-threaded console program is actually all you need. You can transport that to other environments easily (maybe run it under a web framework with minimal changes), and it'll run perfectly on pretty much any build of Python, without any fiddling around. And you spend so little time and code on your UI that way; any half-decently-usable GUI will probably take you a good bit of effort to code, but a good console UI just requires this: something = raw_input("Enter something: ") print("Result: "+result) (Or, better: Upgrade to Python 3, and drop the "raw_" prefix. You get other benefits too.) Play with GUIs later, if at all. Start by getting the guts of your code right. ChrisA