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
This commit is contained in:
parent
738bb57c2b
commit
edb43f70f4
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user