Commit ccde42a9 authored by toshio's avatar toshio

Revert to using a try: except: finally: for locking as the context manager

fails when the lock is stolen out from under it (as from a thread)
parent 446cf202
......@@ -102,17 +102,18 @@ class Prototype:
# Lock the maildir as Maildir.add() is not threadsafe
lock = Lock(os.path.join(config.LOCK_DIR, '%s-maildir.lock'
% mlist.fqdn_listname))
with lock:
try:
lock.lock(timeout=timedelta(seconds=1))
# Add the message to the Maildir
# Message_key could be used to construct the file path if
# necessary::
# os.path.join(archive_dir, mlist.fqdn_listname, 'new',
# message_key)
message_key = mail_box.add(message)
except TimeOutError:
# log the error and go on
elog.error('Unable to lock archive for %s, discarded'
' message: %s' % (mlist.fqdn_listname,
message.get('message-id', '<unknown>')))
try:
lock.lock(timeout=timedelta(seconds=1))
# Add the message to the Maildir
# Message_key could be used to construct the file path if
# necessary::
# os.path.join(archive_dir, mlist.fqdn_listname, 'new',
# message_key)
message_key = mail_box.add(message)
except TimeOutError:
# log the error and go on
elog.error('Unable to lock archive for %s, discarded'
' message: %s' % (mlist.fqdn_listname,
message.get('message-id', '<unknown>')))
finally:
lock.unlock(unconditionally=True)
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