Fixed hup interrupt

main
parent 3b313062e7
commit 4d4c0c30d9

@ -40,6 +40,8 @@ formatter=logging.Formatter('[{asctime}] [{levelname:<8}] {name}: {message}', '%
handler=logging.handlers.RotatingFileHandler(filename='octopimonitor.log', encoding='utf-8', maxBytes=32*1024*1024, backupCount=5)
handler.setFormatter(formatter)
logger.addHandler(handler)
global hupped
hupped=False
def debug(a):
logger.debug(a)
@ -57,12 +59,15 @@ def datestr(time):
return f"{time.year}-{time.month:02}-{time.day:02}"
def trapsignal(signalnum, frame):
global hupped
# https://stackabuse.com/handling-unix-signals-in-python/
info(f"Caught signal {signalnum}")
if signalnum == 1:
info(f"Caught hup - reloading (signal {signalnum})")
(jobdata,lastupdate)=getData()
drawData(jobdata,lastupdate)
hupped=True
debug(f"caugh hup - hupped: {hupped}")
def getData():
@ -164,7 +169,16 @@ try:
drawData(jobdata,lastupdate)
if jobdata['percent'] == "100" or jobdata['bedtarget'] == jobdata['target']:
info("Jobs idle - sleeping for 5 minutes")
time.sleep(300)
delay=10
while delay>0:
time.sleep(30)
delay=delay-1
if hupped:
hupped=False
info(f"Dectected previous hup - breaking out of 5min loop")
break
else:
debug(f"30s sleep loop hupped: {hupped}")
else:
info("Print in progress - sleeping for 30 seconds")
time.sleep(30)

Loading…
Cancel
Save