X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fimport_known_changes.py;h=b403a80880296ac912c76d2458b02738747a753a;hb=df610ec6b921b869c4e4a25629a0aff3f13a03ae;hp=475c8f76433d87b7a8c86abc3da1363085cfd805;hpb=efda164c1f3209e2522f222dfb6553736a10449c;p=dak.git diff --git a/dak/import_known_changes.py b/dak/import_known_changes.py index 475c8f76..b403a808 100755 --- a/dak/import_known_changes.py +++ b/dak/import_known_changes.py @@ -168,6 +168,10 @@ class ChangesGenerator(threading.Thread): threading.Thread.__init__(self) self.queue = queue self.session = DBConn().session() + self.die = False + + def plsDie(self): + self.die = True def run(self): cnf = Config() @@ -181,6 +185,9 @@ class ChangesGenerator(threading.Thread): if not filenames: # Empty directory (or only subdirectories), next continue + if self.die: + return + for changesfile in filenames: if not changesfile.endswith(".changes"): # Only interested in changes files. @@ -198,10 +205,16 @@ class ImportThread(threading.Thread): threading.Thread.__init__(self) self.queue = queue self.session = DBConn().session() + self.die = False + + def plsDie(self): + self.die = True def run(self): while True: try: + if self.die: + return to_import = self.queue.dequeue() if not to_import: return @@ -266,10 +279,25 @@ def main(): queue = OneAtATime() - ChangesGenerator(queue).start() + threads = [ ChangesGenerator(queue) ] for i in range(num_threads): - ImportThread(queue).start() + threads.append( ImportThread(queue) ) + + try: + for thread in threads: + thread.start() + + for thread in thrads: + thread.join() + + except KeyboardInterrupt: + utils.warn("Caught C-c; terminating.") + for thread in threads: + thread.plsDie() + + for thread in threads: + thread.join() if __name__ == '__main__':