def wait(self, timeout=None):
self.__cond.acquire()
try:
if not self.__flag:
self.__cond.wait(timeout)
return self.__flag
finally:
# NOTE(google) Added the try/except. This handles the possibility of
# an asynchronous exception (e.g., DeadlineExceededError) being
# thrown inside of Condition.wait such that it does not re-acquire
# the lock, causing a ThreadError 'release unlocked lock' to be
# raised by Condition.release.
# It is safe to ignore such an error, because it means the lock is
# already released.
try:
self.__cond.release()
except ThreadError:
pass
# Helper to generate new thread names
评论列表
文章目录