[ python-Bugs-1607041 ] Condition.wait timeout fails when system clock changes

SourceForge.net noreply at sourceforge.net
Fri Dec 1 23:35:02 CET 2006


Bugs item #1607041, was opened at 2006-12-01 10:45
Message generated for change (Comment added) made by hashstat
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1607041&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: BC (hashstat)
Assigned to: Nobody/Anonymous (nobody)
Summary: Condition.wait timeout fails when system clock changes

Initial Comment:
If the system clock is adjusted after Condition.wait is called with a timeout, the timeout does not expire as expected.  This appears to be due to the threading.Condition class using the system clock to calculate the timeout expiration without taking system clock changes into account.  Let me illustrate this with an example:


   import threading

   c = threading.Condition()
   c.acquire()
   try:
      ...
      c.wait(3600.0)
      ...
   finally:
      c.release()


Let's say the above snippet is executed at 08:00.  Assuming the condition is never notified, the timeout should expire somewhere close to 09:00.  At 08:30 someone notices that the clock is an hour fast and sets it back to 07:30.  The timeout still expire around 09:00 causing a wait of 2 hours instead of the requested 1 hour.

Now let's say instead that the clock was moved ahead to 09:30 at 08:30.  The timeout would expire immediately after only a 30 minute wait.

----------------------------------------------------------------------

>Comment By: BC (hashstat)
Date: 2006-12-01 14:35

Message:
Logged In: YES 
user_id=939959
Originator: YES

I submitted patch# 1607149 to add checking for clock variations in the
wait method when called with a timeout.

----------------------------------------------------------------------

Comment By: BC (hashstat)
Date: 2006-12-01 13:57

Message:
Logged In: YES 
user_id=939959
Originator: YES

Apparently my description wasn't as clear as I thought.  I don't care
about the clock times in the example.  They were only used to illustrate
the point.  What I do care about is that if a use c.wait(3600) ("wait 60
minutes"), then my thread should wake up in roughly 60 minutes without
regard to changes in the system clock.

With the current Condition implementation, no matter what timeout is used,
setting the system clock ahead reduces or eliminates the wait while setting
the system clock back increases the wait.  So if the clock is set back one
hour in the middle of a 1 microsecond wait (c.wait(1)), wait will return
in an hour and 1 microsecond.  Is this the way it should work?

----------------------------------------------------------------------

Comment By: Jp Calderone (kuran)
Date: 2006-12-01 13:06

Message:
Logged In: YES 
user_id=366566
Originator: NO

Why should it work that way?

c.wait(3600) doesn't say "wait until 0900", it says "wait 60 minutes".

If you want c.waitUntil(9 oclock), maybe that would be a good API
addition, but it definitely should be a separate method.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1607041&group_id=5470


More information about the Python-bugs-list mailing list