Commit bb1ba3b2 authored by Colomban Wendling's avatar Colomban Wendling

Mail thread: only report a task done when we actually handled a task

Don't account for a task in the `finally` handler as we actually got a
task only if we didn't receive an exception.  This cleans up the code
and possibly fixes it if we ever get any other exception than a
timeout.
parent 8cf30efb
......@@ -46,12 +46,10 @@ class ThreadedSMTP(object):
server = None
while self._loop or not self._queue.empty():
task_eaten = True
try:
args, kwargs = self._queue.get(timeout=timeout)
except queue.Empty:
server = self.__server_quit(server)
task_eaten = False # we didn't eat a task, just timeout
else:
if len(args) or len(kwargs): # ignore empty items
try:
......@@ -60,9 +58,7 @@ class ThreadedSMTP(object):
server.sendmail(*args, **kwargs)
except Exception as e:
logging.warning("Couldn't send email: %s" % str(e))
finally:
if task_eaten:
self._queue.task_done()
self._queue.task_done()
self.__server_quit(server)
def sendmail(self, *args, **kwargs):
......
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