Reconnect correctly after ping timeouts
This commit is contained in:
parent
9b64dc3995
commit
b142c501e7
@ -88,13 +88,14 @@ class IRCCore(object):
|
||||
logging.info("Reconnecting in 3s...")
|
||||
await asyncio.sleep(3)
|
||||
|
||||
async def kill(self, message="Help! Another thread is killing me :("):
|
||||
async def kill(self, message="Help! Another thread is killing me :(", forever=True):
|
||||
"""Send quit message, flush queue, and close the socket
|
||||
|
||||
:param message: Quit message to send before disconnecting
|
||||
:type message: str
|
||||
"""
|
||||
self.alive = False
|
||||
if forever:
|
||||
self.alive = False
|
||||
self.act_QUIT(message) # TODO will this hang if the socket is having issues?
|
||||
await self.writer.drain()
|
||||
self.writer.close()
|
||||
|
@ -59,6 +59,6 @@ class PingRespondTimer(Thread):
|
||||
sleep(5)
|
||||
if time() - self.lastping > self.master.config.get("activity_timeout", 300):
|
||||
self.master.log.info("No activity in %s seconds. Reconnecting" % str(time() - self.lastping))
|
||||
self.master.bot.disconnect("Reconnecting...")
|
||||
self.master.bot.kill("Ping timeout", forever=False)
|
||||
self.reset()
|
||||
|
||||
|
@ -92,16 +92,20 @@ class PyIRCBot(object):
|
||||
self.log.info("disconnect")
|
||||
self.kill(message=message)
|
||||
|
||||
def kill(self, message="Help! Another thread is killing me :("):
|
||||
"""Shut down the bot violently
|
||||
def break_connection(self):
|
||||
"""Break the connection, e.g. in the case of an unresponsive server"""
|
||||
|
||||
def kill(self, message="Help! Another thread is killing me :(", forever=True):
|
||||
"""Close the connection violently
|
||||
|
||||
:param sys_exit: True causes sys.exit(0) to be called
|
||||
:type sys_exit: bool
|
||||
:param message: Quit message
|
||||
:type message: str
|
||||
"""
|
||||
self.closeAllModules()
|
||||
asyncio.run_coroutine_threadsafe(self.irc.kill(message=message), self.loop)
|
||||
if forever:
|
||||
self.closeAllModules()
|
||||
asyncio.run_coroutine_threadsafe(self.irc.kill(message=message, forever=forever), self.loop)
|
||||
|
||||
def initModules(self):
|
||||
"""load modules specified in instance config"""
|
||||
|
Loading…
Reference in New Issue
Block a user