Condition.wait(0.5) doesn't respect it's timeout

stephane.bisinger at gmail.com stephane.bisinger at gmail.com
Sun Apr 19 15:41:33 EDT 2009


On Apr 19, 7:21 pm, Piet van Oostrum <p... at cs.uu.nl> wrote:
>                 while time.time() - t < 0.5 or not self._modified:
>                     print >> sys.stderr, "Going to sleep\n"
>                     self._mod_lock.wait(timeout=1)
>                     print >> sys.stderr, "Ok time to see if we must repaint"
>                 self.__repaint()
>                 t = time.time()
>
> But the timeout thing will continue after that, so you have a continuous
> polling loop which wastes some CPU time. I think what you want can be
> more easily achieved by doing a sleep(0.5) before the outer while loop,
> i.e. as the first statement in __thread_run.

Two boolean checks every half second is not a great waste; but
thinking about your solution I've come to agree that it is smarter and
more effective. Thank you again!



More information about the Python-list mailing list