Gracefully handle sigint

This commit is contained in:
simon 2019-12-19 10:53:20 -05:00
parent 2aefd2c3a2
commit 7ea1612b32
2 changed files with 12 additions and 2 deletions

12
run.py
View File

@ -153,6 +153,8 @@ def publish_worker(queue: Queue, helper, p):
while True: while True:
try: try:
item, board = queue.get() item, board = queue.get()
if item is None:
break
publish(item, board, helper, channel, web) publish(item, board, helper, channel, web)
except Exception as e: except Exception as e:
@ -243,9 +245,15 @@ if __name__ == "__main__":
publish_q = Queue() publish_q = Queue()
for _ in range(5): for _ in range(5):
publish_thread = Thread(target=publish_worker, args=(publish_q, chan_helper, proxy)) publish_thread = Thread(target=publish_worker, args=(publish_q, chan_helper, proxy))
publish_thread.setDaemon(True)
publish_thread.start() publish_thread.start()
s = ChanScanner(chan_helper, proxy) s = ChanScanner(chan_helper, proxy)
while True: while True:
for p, b in s.all_posts(): try:
publish_q.put((p, b)) for p, b in s.all_posts():
publish_q.put((p, b))
except KeyboardInterrupt as e:
for _ in range(5):
publish_q.put((None, None))
break

View File

@ -70,6 +70,8 @@ class Web:
}, },
}]) }])
return r return r
except KeyboardInterrupt as e:
raise e
except Exception as e: except Exception as e:
logger.error(str(e) + traceback.format_exc()) logger.error(str(e) + traceback.format_exc())
if self.monitoring: if self.monitoring: