--- old/threading.py 2006-12-01 22:14:19.000000000 +0000 +++ new/threading.py 2006-12-01 22:12:26.000000000 +0000 @@ -209,13 +209,26 @@ # we'll be unresponsive. The scheme here sleeps very # little at first, longer as time goes on, but never longer # than 20 times per second (or the timeout time remaining). - endtime = _time() + timeout + time = _time() + endtime = time + timeout delay = 0.0005 # 500 us -> initial delay of 1 ms while True: gotit = waiter.acquire(0) if gotit: break - remaining = endtime - _time() + lasttime = time + time = _time() + delta = time - lasttime + # If the current time is smaller than the last polled time, + # the system clock was set back and must be adjusted for. + # If the delta was sufficiently large (greater than 10 + # seconds), then the system clock was probably set forward + # and should be adjusted for. The 10 second window could + # optionally be made a tunable parameter for applications + # where 10 seconds is unreasonable. + if delta < 0.0 or delta > 10.0: + endtime += delta - delay + remaining = endtime - time if remaining <= 0: break delay = min(delay * 2, remaining, .05)