summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshangxdy <shang.xiaodong@zte.com.cn>2018-01-04 10:24:06 +0800
committershangxdy <shang.xiaodong@zte.com.cn>2018-01-26 15:31:37 +0800
commit8a76de29e1ceebcde517c6491de190de4e005303 (patch)
tree10ca5b2920d9d409e50282597b935fcbb0a0a43b
parent49d4bef593537a8b6b19c83152cb94d97dbdaeda (diff)
downloadgear-8a76de29e1ceebcde517c6491de190de4e005303.tar.gz
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 <shang.xiaodong@zte.com.cn>
-rw-r--r--gear/__init__.py21
1 files 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