Catch SIGHUP: deep reload
This commit is contained in:
parent
7440bd4222
commit
29913bd943
@ -155,14 +155,40 @@ def main():
|
|||||||
__import__(module)
|
__import__(module)
|
||||||
|
|
||||||
# Signals handling
|
# Signals handling
|
||||||
def sighandler(signum, frame):
|
def sigtermhandler(signum, frame):
|
||||||
|
"""On SIGTERM and SIGINT, quit nicely"""
|
||||||
context.quit()
|
context.quit()
|
||||||
signal.signal(signal.SIGINT, sighandler)
|
signal.signal(signal.SIGINT, sigtermhandler)
|
||||||
signal.signal(signal.SIGTERM, sighandler)
|
signal.signal(signal.SIGTERM, sigtermhandler)
|
||||||
|
|
||||||
|
def sighuphandler(signum, frame):
|
||||||
|
"""On SIGHUP, perform a deep reload"""
|
||||||
|
import imp
|
||||||
|
|
||||||
|
# Reload nemubot Python modules
|
||||||
|
imp.reload(nemubot)
|
||||||
|
nemubot.reload()
|
||||||
|
|
||||||
|
# Hotswap context
|
||||||
|
import nemubot.bot
|
||||||
|
context = nemubot.bot.hotswap(context)
|
||||||
|
|
||||||
|
# Reload configuration file
|
||||||
|
for path in args.files:
|
||||||
|
if os.path.isfile(path):
|
||||||
|
context.sync_queue.put_nowait(["loadconf", path])
|
||||||
|
signal.signal(signal.SIGHUP, sighuphandler)
|
||||||
|
|
||||||
|
# Here we go!
|
||||||
context.start()
|
context.start()
|
||||||
|
|
||||||
|
# context can change when performing an hotswap, always join the latest context
|
||||||
|
oldcontext = None
|
||||||
|
while oldcontext != context:
|
||||||
|
oldcontext = context
|
||||||
context.join()
|
context.join()
|
||||||
|
|
||||||
|
# Wait for consumers
|
||||||
logger.info("Waiting for other threads shuts down...")
|
logger.info("Waiting for other threads shuts down...")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user