Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #73366

Re: Under what kind of situation, time.sleep(n) would sleep much longer than n seconds?

Newsgroups comp.lang.python
Date 2014-06-18 08:24 -0700
References <713f4189-5ffe-492d-9c7d-447bb4b4928a@googlegroups.com> <mailman.11114.1403087670.18130.python-list@python.org>
Message-ID <4d7c474a-b88e-4dea-b74c-ed34f4969310@googlegroups.com> (permalink)
Subject Re: Under what kind of situation, time.sleep(n) would sleep much longer than n seconds?
From crow <wentlv@gmail.com>

Show all headers | View raw


Hi, Chris & Marko

Thanks for your reply.

I find the reason why my time.sleep take longer time.
In my script, I use wxPython to build up my GUI, and I open another thread to do network communications.
It turned out that if you create a wx.Frame & make it show up, then your time.sleep may sleep longer time than expected.

I will dig deeper for the root cause. Anyway, it's interesting.

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()

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Under what kind of situation, time.sleep(n) would sleep much longer than n seconds? crow <wentlv@gmail.com> - 2014-06-18 02:52 -0700
  Re: Under what kind of situation, time.sleep(n) would sleep much longer than n seconds? Marko Rauhamaa <marko@pacujo.net> - 2014-06-18 13:30 +0300
  Re: Under what kind of situation, time.sleep(n) would sleep much longer than n seconds? Chris Angelico <rosuav@gmail.com> - 2014-06-18 20:34 +1000
    Re: Under what kind of situation, time.sleep(n) would sleep much longer than n seconds? crow <wentlv@gmail.com> - 2014-06-18 08:24 -0700
      Re: Under what kind of situation, time.sleep(n) would sleep much longer than n seconds? Chris Angelico <rosuav@gmail.com> - 2014-06-19 09:38 +1000
        Re: Under what kind of situation, time.sleep(n) would sleep much longer than n seconds? crow <wentlv@gmail.com> - 2014-06-18 18:41 -0700
          Re: Under what kind of situation, time.sleep(n) would sleep much longer than n seconds? Chris Angelico <rosuav@gmail.com> - 2014-06-19 13:58 +1000
        Re: Under what kind of situation, time.sleep(n) would sleep much longer than n seconds? Christian Gollwitzer <auriocus@gmx.de> - 2014-06-19 09:18 +0200
          Re: Under what kind of situation, time.sleep(n) would sleep much longer than n seconds? Chris Angelico <rosuav@gmail.com> - 2014-06-19 17:42 +1000
            Re: Under what kind of situation, time.sleep(n) would sleep much longer than n seconds? Marko Rauhamaa <marko@pacujo.net> - 2014-06-19 12:20 +0300
            Re: Under what kind of situation, time.sleep(n) would sleep much longer than n seconds? Christian Gollwitzer <auriocus@gmx.de> - 2014-06-19 19:17 +0200
              Re: Under what kind of situation, time.sleep(n) would sleep much longer than n seconds? Chris Angelico <rosuav@gmail.com> - 2014-06-20 08:57 +1000
          Re: Under what kind of situation, time.sleep(n) would sleep much longer than n seconds? Terry Reedy <tjreedy@udel.edu> - 2014-06-19 22:33 -0400
          Re: Under what kind of situation, time.sleep(n) would sleep much longer than n seconds? Chris Angelico <rosuav@gmail.com> - 2014-06-20 12:54 +1000

csiph-web