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...")
|
logging.info("Reconnecting in 3s...")
|
||||||
await asyncio.sleep(3)
|
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
|
"""Send quit message, flush queue, and close the socket
|
||||||
|
|
||||||
:param message: Quit message to send before disconnecting
|
:param message: Quit message to send before disconnecting
|
||||||
:type message: str
|
: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?
|
self.act_QUIT(message) # TODO will this hang if the socket is having issues?
|
||||||
await self.writer.drain()
|
await self.writer.drain()
|
||||||
self.writer.close()
|
self.writer.close()
|
||||||
|
|
|
@ -59,6 +59,6 @@ class PingRespondTimer(Thread):
|
||||||
sleep(5)
|
sleep(5)
|
||||||
if time() - self.lastping > self.master.config.get("activity_timeout", 300):
|
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.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()
|
self.reset()
|
||||||
|
|
||||||
|
|
|
@ -92,16 +92,20 @@ class PyIRCBot(object):
|
||||||
self.log.info("disconnect")
|
self.log.info("disconnect")
|
||||||
self.kill(message=message)
|
self.kill(message=message)
|
||||||
|
|
||||||
def kill(self, message="Help! Another thread is killing me :("):
|
def break_connection(self):
|
||||||
"""Shut down the bot violently
|
"""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
|
:param sys_exit: True causes sys.exit(0) to be called
|
||||||
:type sys_exit: bool
|
:type sys_exit: bool
|
||||||
:param message: Quit message
|
:param message: Quit message
|
||||||
:type message: str
|
:type message: str
|
||||||
"""
|
"""
|
||||||
self.closeAllModules()
|
if forever:
|
||||||
asyncio.run_coroutine_threadsafe(self.irc.kill(message=message), self.loop)
|
self.closeAllModules()
|
||||||
|
asyncio.run_coroutine_threadsafe(self.irc.kill(message=message, forever=forever), self.loop)
|
||||||
|
|
||||||
def initModules(self):
|
def initModules(self):
|
||||||
"""load modules specified in instance config"""
|
"""load modules specified in instance config"""
|
||||||
|
|
Loading…
Reference in New Issue