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
This commit is contained in:
Sam Thursfield 2015-05-19 15:27:30 +01:00
parent bb681360fc
commit 0558e173e9
1 changed files with 1 additions and 1 deletions

View File

@ -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