From edb43f70f41d92d2434c73e4cc8375fe39c456f1 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Wed, 2 Oct 2013 22:14:45 +1300 Subject: [PATCH] Allow ctrl-Cing gerritlib programs. If the GerritWatcher thread is not set as daemon, the program won't exit when the main thread exits. This is usually undesirable. As part of making the thread be a daemon, I've moved the ownership of threading logic to the gerrit startWatching method, decoupling GerritWatcher's logic from the implementation detail of being a thread (vs a co-process etc). Change-Id: Ib28d5bfec47d2c4c88b99e07dec50ee4dd0104bf --- gerritlib/gerrit.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gerritlib/gerrit.py b/gerritlib/gerrit.py index 510c124..f3c84c4 100644 --- a/gerritlib/gerrit.py +++ b/gerritlib/gerrit.py @@ -24,7 +24,7 @@ import time import paramiko -class GerritWatcher(threading.Thread): +class GerritWatcher(object): log = logging.getLogger("gerrit.GerritWatcher") def __init__( @@ -37,7 +37,6 @@ class GerritWatcher(threading.Thread): All other parameters are optional and if not supplied are sourced from the gerrit instance. """ - threading.Thread.__init__(self) self.username = username or gerrit.username self.keyfile = keyfile or gerrit.keyfile self.hostname = hostname or gerrit.hostname @@ -104,7 +103,8 @@ class Gerrit(object): def startWatching(self): self.event_queue = Queue.Queue() - self.watcher_thread = GerritWatcher(self) + self.watcher_thread = threading.Thread(target=GerritWatcher(self).run) + self.watcher_thread.daemon = True self.watcher_thread.start() def addEvent(self, data):