From 62a3c0072d27dcc7c0ed94f631cc769426d5e03b Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 2 Oct 2012 17:33:17 -0400 Subject: [PATCH] Exit cleanly on control-C. --- irkerd | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/irkerd b/irkerd index 9d98d5e..bbd11a0 100755 --- a/irkerd +++ b/irkerd @@ -114,6 +114,7 @@ class Connection: # The consumer thread self.queue = Queue.Queue() self.thread = threading.Thread(target=self.dequeue) + self.thread.daemon = True self.thread.start() def nickname(self, n=None): "Return a name for the nth server connection." @@ -303,6 +304,7 @@ class Irker: self.irc.add_global_handler("disconnect", self._handle_disconnect) self.irc.add_global_handler("kick", self._handle_kick) thread = threading.Thread(target=self.irc.process_forever) + thread.daemon = True self.irc._thread = thread thread.start() self.servers = {} @@ -444,13 +446,17 @@ if __name__ == '__main__': sys.exit(0) irker = Irker(debuglevel=debuglvl) tcpserver = SocketServer.TCPServer((HOST, PORT), IrkerTCPHandler) + tcpserver = threading.Thread(target=tcpserver.serve_forever) + tcpserver.daemon = True + tcpserver.start() udpserver = SocketServer.UDPServer((HOST, PORT), IrkerUDPHandler) - threading.Thread(target=tcpserver.serve_forever).start() - threading.Thread(target=udpserver.serve_forever).start() - # Main thread has to stay alive forever for the cooperative - # scheduling of the green threads to work. - if green_threads: + udpserver = threading.Thread(target=udpserver.serve_forever) + udpserver.daemon = True + udpserver.start() + try: while True: time.sleep(10) + except KeyboardInterrupt: + raise SystemExit, 1 # end -- 2.26.2