From a9adbff3df8384d73282d558ae5e52591a874820 Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Sun, 2 Feb 2003 19:24:38 +0000 Subject: [PATCH] backport: revision 1.29 date: 2002/11/21 21:08:39; author: gvanrossum; state: Exp; lines: +14 -8 The _Event class should be more careful with releasing its lock when interrupted. A try/finally will do nicely. Maybe other classes need this too, but since they manipulate more state it's less clear that that is always the right thing, and I'm in a hurry. --- Lib/threading.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Lib/threading.py b/Lib/threading.py index 9763c629d8d2..ffbeb0ed618e 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -316,20 +316,26 @@ class _Event(_Verbose): def set(self): self.__cond.acquire() - self.__flag = 1 - self.__cond.notifyAll() - self.__cond.release() + try: + self.__flag = 1 + self.__cond.notifyAll() + finally: + self.__cond.release() def clear(self): self.__cond.acquire() - self.__flag = 0 - self.__cond.release() + try: + self.__flag = 0 + finally: + self.__cond.release() def wait(self, timeout=None): self.__cond.acquire() - if not self.__flag: - self.__cond.wait(timeout) - self.__cond.release() + try: + if not self.__flag: + self.__cond.wait(timeout) + finally: + self.__cond.release() # Helper to generate new thread names _counter = 0 -- 2.47.3