Replace spam.acquire() try: ... finally: spam.release() with "with spam:"

This commit is contained in:
Gregory P. Smith 2008-01-22 01:12:02 +00:00
parent c64386b595
commit 64c5677de4
1 changed files with 8 additions and 24 deletions

View File

@ -347,27 +347,18 @@ class _Event(_Verbose):
return self.__flag return self.__flag
def set(self): def set(self):
self.__cond.acquire() with self.__cond:
try:
self.__flag = True self.__flag = True
self.__cond.notifyAll() self.__cond.notifyAll()
finally:
self.__cond.release()
def clear(self): def clear(self):
self.__cond.acquire() with self.__cond:
try:
self.__flag = False self.__flag = False
finally:
self.__cond.release()
def wait(self, timeout=None): def wait(self, timeout=None):
self.__cond.acquire() with self.__cond:
try:
if not self.__flag: if not self.__flag:
self.__cond.wait(timeout) self.__cond.wait(timeout)
finally:
self.__cond.release()
# Helper to generate new thread names # Helper to generate new thread names
_counter = 0 _counter = 0
@ -531,10 +522,9 @@ class Thread(_Verbose):
pass pass
def __stop(self): def __stop(self):
self.__block.acquire() with self.__block:
self.__stopped = True self.__stopped = True
self.__block.notifyAll() self.__block.notifyAll()
self.__block.release()
def __delete(self): def __delete(self):
"Remove current thread from the dict of currently running threads." "Remove current thread from the dict of currently running threads."
@ -560,15 +550,12 @@ class Thread(_Verbose):
# since it isn't if dummy_threading is *not* being used then don't # since it isn't if dummy_threading is *not* being used then don't
# hide the exception. # hide the exception.
_active_limbo_lock.acquire() with _active_limbo_lock:
try:
try: try:
del _active[_get_ident()] del _active[_get_ident()]
except KeyError: except KeyError:
if 'dummy_threading' not in _sys.modules: if 'dummy_threading' not in _sys.modules:
raise raise
finally:
_active_limbo_lock.release()
def join(self, timeout=None): def join(self, timeout=None):
if not self.__initialized: if not self.__initialized:
@ -581,8 +568,7 @@ class Thread(_Verbose):
if __debug__: if __debug__:
if not self.__stopped: if not self.__stopped:
self._note("%s.join(): waiting until thread stops", self) self._note("%s.join(): waiting until thread stops", self)
self.__block.acquire() with self.__block:
try:
if timeout is None: if timeout is None:
while not self.__stopped: while not self.__stopped:
self.__block.wait() self.__block.wait()
@ -600,8 +586,6 @@ class Thread(_Verbose):
else: else:
if __debug__: if __debug__:
self._note("%s.join(): thread stopped", self) self._note("%s.join(): thread stopped", self)
finally:
self.__block.release()
def getName(self): def getName(self):
assert self.__initialized, "Thread.__init__() not called" assert self.__initialized, "Thread.__init__() not called"