Make RPC be a daemon thread for cleaner exiting

This commit is contained in:
dave 2014-10-07 19:25:30 -07:00
parent 764642e34b
commit bce1645635
2 changed files with 8 additions and 8 deletions

View File

@ -71,13 +71,13 @@ class PyIRCBot(asynchat.async_chat):
# self.rpc.server._Server__transport.shutdown(SHUT_RDWR) # self.rpc.server._Server__transport.shutdown(SHUT_RDWR)
#except Exception as e: #except Exception as e:
# self.log.error(str(e)) # self.log.error(str(e))
try: #try:
self.rpc.server._Server__transport.close() # self.rpc.server._Server__transport.close()
except Exception as e: #except Exception as e:
self.log.error(str(e)) # self.log.error(str(e))
#Kill RPC thread #Kill RPC thread
self.rpc._stop() #self.rpc._stop()
#Close all modules #Close all modules
self.closeAllModules() self.closeAllModules()
@ -96,7 +96,7 @@ class PyIRCBot(asynchat.async_chat):
:param data: the data that was recieved :param data: the data that was recieved
:type data: str""" :type data: str"""
self.log.debug("<< %(message)s", {"message":repr(data)}) #self.log.debug("<< %(message)s", {"message":repr(data)})
self.buffer.write(data) self.buffer.write(data)
def found_terminator(self): def found_terminator(self):
@ -153,7 +153,7 @@ class PyIRCBot(asynchat.async_chat):
:param text: the string to send :param text: the string to send
:type text: str""" :type text: str"""
if self.connected: if self.connected:
self.log.debug(">> "+text) #self.log.debug(">> "+text)
self.send( (text+"\r\n").encode("UTF-8").decode().encode("UTF-8")) self.send( (text+"\r\n").encode("UTF-8").decode().encode("UTF-8"))
else: else:
self.log.warning("Send attempted while disconnected. >> "+text) self.log.warning("Send attempted while disconnected. >> "+text)

View File

@ -13,7 +13,7 @@ from threading import Thread
class BotRPC(Thread): class BotRPC(Thread):
def __init__(self, main): def __init__(self, main):
Thread.__init__(self) Thread.__init__(self, daemon=True)
self.bot = main self.bot = main
self.log = logging.getLogger('RPC') self.log = logging.getLogger('RPC')
self.server = jsonrpc.Server(jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=(self.bot.botconfig["bot"]["rpcbind"], self.bot.botconfig["bot"]["rpcport"]))) self.server = jsonrpc.Server(jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=(self.bot.botconfig["bot"]["rpcbind"], self.bot.botconfig["bot"]["rpcport"])))