fix<process_email>: free the log file handler after it's not used anymore

This commit is contained in:
Arkadiy Korotaev 2020-02-12 20:53:00 +01:00
parent 354debb618
commit 1643a45457
No known key found for this signature in database
GPG Key ID: 4BD092DD84540FAB

View File

@ -74,6 +74,8 @@ def process_email(quiet=False):
if quiet:
logger.propagate = False # do not propagate to root logger that would log to console
logdir = q.logging_dir or '/var/log/helpdesk/'
try:
handler = logging.FileHandler(join(logdir, q.slug + '_get_email.log'))
logger.addHandler(handler)
@ -86,6 +88,15 @@ def process_email(quiet=False):
process_queue(q, logger=logger)
q.email_box_last_check = timezone.now()
q.save()
finally:
try:
handler.close()
except Exception as e:
logging.exception(e)
try:
logger.removeHandler(handler)
except Exception as e:
logging.exception(e)
def pop3_sync(q, logger, server):