diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-04-02 20:15:57 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-04-02 20:15:57 (GMT) |
commit | c951bf91283996587246328c49e4b1909883db8c (patch) | |
tree | 8711f8334724d80d789fc5baa0684ef709388978 /Lib/threading.py | |
parent | f5bd6843377a4f4433700282f5c4bddb3d6333ae (diff) | |
download | cpython-c951bf91283996587246328c49e4b1909883db8c.zip cpython-c951bf91283996587246328c49e4b1909883db8c.tar.gz cpython-c951bf91283996587246328c49e4b1909883db8c.tar.bz2 |
SF bug [#410708] Condition.wait() and KeyboardInterrupt.
http://sourceforge.net/tracker/?func=detail&aid=410708&group_id=5470&atid=105470
Added try/finally around Condition.wait() guts, so that the lock state gets
restored at the end no matter what happens.
Diffstat (limited to 'Lib/threading.py')
-rw-r--r-- | Lib/threading.py | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/Lib/threading.py b/Lib/threading.py index e484521..c5e65d9 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -185,31 +185,33 @@ class _Condition(_Verbose): waiter.acquire() self.__waiters.append(waiter) saved_state = self._release_save() - if timeout is None: - waiter.acquire() - if __debug__: - self._note("%s.wait(): got it", self) - else: - endtime = _time() + timeout - delay = 0.000001 # 1 usec - while 1: - gotit = waiter.acquire(0) - if gotit or _time() >= endtime: - break - _sleep(delay) - if delay < 1.0: - delay = delay * 2.0 - if not gotit: + try: # restore state no matter what (e.g., KeyboardInterrupt) + if timeout is None: + waiter.acquire() if __debug__: - self._note("%s.wait(%s): timed out", self, timeout) - try: - self.__waiters.remove(waiter) - except ValueError: - pass + self._note("%s.wait(): got it", self) else: - if __debug__: - self._note("%s.wait(%s): got it", self, timeout) - self._acquire_restore(saved_state) + endtime = _time() + timeout + delay = 0.000001 # 1 usec + while 1: + gotit = waiter.acquire(0) + if gotit or _time() >= endtime: + break + _sleep(delay) + if delay < 1.0: + delay = delay * 2.0 + if not gotit: + if __debug__: + self._note("%s.wait(%s): timed out", self, timeout) + try: + self.__waiters.remove(waiter) + except ValueError: + pass + else: + if __debug__: + self._note("%s.wait(%s): got it", self, timeout) + finally: + self._acquire_restore(saved_state) def notify(self, n=1): me = currentThread() |