From 7a38c05f12145103faccb1aa3002f4cf3640f583 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Tue, 31 Jul 2018 20:19:43 +0200 Subject: [PATCH] Stop e-mail-thread on quit or restart --- cps/asyncmail.py | 10 +++++++--- cps/server.py | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cps/asyncmail.py b/cps/asyncmail.py index d8ded413..7ff57946 100644 --- a/cps/asyncmail.py +++ b/cps/asyncmail.py @@ -84,6 +84,7 @@ class email_SSL(email): class EMailThread(threading.Thread): def __init__(self): + self._stopevent = threading.Event() threading.Thread.__init__(self) self.status = 0 self.current = 0 @@ -93,16 +94,19 @@ class EMailThread(threading.Thread): self.asyncSMTP=None def run(self): - while 1: + while not self._stopevent.isSet(): doLock = threading.Lock() doLock.acquire() if self.current != self.last: doLock.release() self.send_raw_email() self.current += 1 - + doLock.release() time.sleep(1) + def stop(self): + self._stopevent.set() + def get_send_status(self): if self.asyncSMTP: return self.asyncSMTP.getTransferStatus() @@ -134,7 +138,7 @@ class EMailThread(threading.Thread): # if more than 50 entries in the list, clean the list addLock = threading.Lock() addLock.acquire() - if self.last >= 3: + if self.last >= 20: self.delete_completed_tasks() # progress, runtime, and status = 0 self.queue.append({'data':data, 'settings':settings, 'recipent':recipient, 'starttime': 0, diff --git a/cps/server.py b/cps/server.py index fbfffb45..455dad17 100644 --- a/cps/server.py +++ b/cps/server.py @@ -70,6 +70,7 @@ class server: if self.restart == True: web.app.logger.info("Performing restart of Calibre-web") + web.helper.global_eMailThread.stop() if os.name == 'nt': arguments = ["\"" + sys.executable + "\""] for e in sys.argv: @@ -79,6 +80,7 @@ class server: os.execl(sys.executable, sys.executable, *sys.argv) else: web.app.logger.info("Performing shutdown of Calibre-web") + web.helper.global_eMailThread.stop() sys.exit(0) def setRestartTyp(self,starttyp):