Commit 3c87d5ae authored by Colomban Wendling's avatar Colomban Wendling

Mails: properly pop eaten item even if the server is not started

This fixes ThreadedSMTP.quit() when the connection to the server is
down as Queue.join() will wait for all tasks to be popped and accounted
for, but we wouldn't account for the fake (empty) task because the
connection to the server would not be open.

So, properly differentiate a closed connection from a queue timeout.
parent 96909d62
...@@ -43,10 +43,12 @@ class ThreadedSMTP(object): ...@@ -43,10 +43,12 @@ class ThreadedSMTP(object):
server = None server = None
while self._loop or not self._queue.empty(): while self._loop or not self._queue.empty():
task_eaten = True
try: try:
args, kwargs = self._queue.get(timeout=timeout) args, kwargs = self._queue.get(timeout=timeout)
except queue.Empty: except queue.Empty:
server = self.__server_quit(server) server = self.__server_quit(server)
task_eaten = False # we didn't eat a task, just timeout
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
break break
else: else:
...@@ -58,7 +60,7 @@ class ThreadedSMTP(object): ...@@ -58,7 +60,7 @@ class ThreadedSMTP(object):
except Exception as e: except Exception as e:
logging.warning("Couldn't send email: %s" % str(e)) logging.warning("Couldn't send email: %s" % str(e))
finally: finally:
if server: # server is None on exception queue.Empty if task_eaten:
self._queue.task_done() self._queue.task_done()
self.__server_quit(server) self.__server_quit(server)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment