From 8a76de29e1ceebcde517c6491de190de4e005303 Mon Sep 17 00:00:00 2001 From: shangxdy Date: Thu, 4 Jan 2018 10:24:06 +0800 Subject: Modify connection timeout process When connection to gearman server is timeout, it's necessary to release lock before raising a exception, otherwise the client may be dead locked. Change-Id: Idc9c9c4bd439b122dc7855ca05d962c4e6687829 Signed-off-by: shangxdy --- gear/__init__.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/gear/__init__.py b/gear/__init__.py index 0a78fe4..7695490 100644 --- a/gear/__init__.py +++ b/gear/__init__.py @@ -1221,15 +1221,18 @@ class BaseClient(BaseClientServer): start_time = time.time() while self.running: self.connections_condition.acquire() - while self.running and not self.active_connections: - if timeout is not None: - self._checkTimeout(start_time, timeout) - self.log.debug("Waiting for at least one active connection") - self.connections_condition.wait(timeout=1) - if self.active_connections: - self.log.debug("Active connection found") - connected = True - self.connections_condition.release() + try: + while self.running and not self.active_connections: + if timeout is not None: + self._checkTimeout(start_time, timeout) + self.log.debug("Waiting for at least one active " + "connection") + self.connections_condition.wait(timeout=1) + if self.active_connections: + self.log.debug("Active connection found") + connected = True + finally: + self.connections_condition.release() if connected: return -- cgit v1.2.1