summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2015-05-19 15:27:30 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2015-05-19 15:05:25 +0000
commit0558e173e9d3b27fb7dc363e306eaf5109511729 (patch)
treeb9a4901704fd108a79268416967ae5c90638620f
parentbb681360fcbcbb9a9b53f7e0fc02a752996a3cf3 (diff)
downloadgear-0558e173e9d3b27fb7dc363e306eaf5109511729.tar.gz
Handle SIGINT correctly in Client.waitForServer()
The Python 2.7 threading.Condition.wait() function will block the process from responding to any signals until the condition triggers. This was especially bad for commandline applications. Before this commit, if an application didn't manage to connect to the Gearman server it would block forever and ignore CTRL+C. Adding a 'timeout' works around this issue. Behaviour is unchanged except that the 'Waiting for at least one active connection' debug message will now be logged once per second. This problem is fixed upstream in Python 3.2: <https://bugs.python.org/issue8844> Change-Id: Ib1043948b1b37a4a6732176314b8a243aad73397
-rw-r--r--gear/__init__.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/gear/__init__.py b/gear/__init__.py
index 51c0c91..b19d386 100644
--- a/gear/__init__.py
+++ b/gear/__init__.py
@@ -1196,7 +1196,7 @@ class BaseClient(BaseClientServer):
self.connections_condition.acquire()
while self.running and not self.active_connections:
self.log.debug("Waiting for at least one active connection")
- self.connections_condition.wait()
+ self.connections_condition.wait(timeout=1)
if self.active_connections:
self.log.debug("Active connection found")
connected = True