summaryrefslogtreecommitdiff
path: root/Mailman/MailList.py
diff options
context:
space:
mode:
authorbwarsaw1999-08-21 04:46:31 +0000
committerbwarsaw1999-08-21 04:46:31 +0000
commit7a65eed3b335d9c8f688bcada7b5d87836564c12 (patch)
treedf9b3ee60b39ce7142b76813495f1cf45ea90b16 /Mailman/MailList.py
parent221aff3fcb5fe7be8ac36d940107beea8c8e6ace (diff)
downloadmailman-7a65eed3b335d9c8f688bcada7b5d87836564c12.tar.gz
mailman-7a65eed3b335d9c8f688bcada7b5d87836564c12.tar.zst
mailman-7a65eed3b335d9c8f688bcada7b5d87836564c12.zip
Ditch the posix lockfile stuff in favor of the now "standard" LockFile
module. Specifically: __del__(): Be sure to unlock the list when it gets GC'd InitTempVars(): _tmp_lock => __createlock_p _lock_file => __lock __lock is now a LockFile object and all locking goes through this object. Load(): _tmp_lock => __createlock_p Locked(), Lock(), Unlock(): Use the new LockFile object as the basis for locking. Also, Unlock() should catch AlreadyLockedError for backwards compatable semantics.
Diffstat (limited to 'Mailman/MailList.py')
-rw-r--r--Mailman/MailList.py50
1 files changed, 21 insertions, 29 deletions
diff --git a/Mailman/MailList.py b/Mailman/MailList.py
index ff55d00f1..2751f5a7e 100644
--- a/Mailman/MailList.py
+++ b/Mailman/MailList.py
@@ -42,6 +42,7 @@ from SecurityManager import SecurityManager
from Bouncer import Bouncer
from GatewayManager import GatewayManager
from Mailman.Logging.StampedLogger import StampedLogger
+import LockFile
# Note:
# an _ in front of a member variable for the MailList class indicates
@@ -67,6 +68,7 @@ class MailList(MailCommandHandler, HTMLFormatter, Deliverer, ListAdmin,
except AttributeError:
# List may not have gotten far enough to have proper _log_files!
pass
+ self.Unlock()
def GetMembers(self):
"""returns a list of the members. (all lowercase)"""
@@ -257,8 +259,11 @@ class MailList(MailCommandHandler, HTMLFormatter, Deliverer, ListAdmin,
def InitTempVars(self, name, lock):
"""Set transient variables of this and inherited classes."""
- self._tmp_lock = lock
- self._lock_file = None
+ self.__createlock_p = lock
+ self.__lock = LockFile.LockFile(
+ os.path.join(mm_cfg.LOCK_DIR, name) + '.lock',
+ # TBD: is this a good choice of lifetime?
+ lifetime = 60)
self._internal_name = name
self._ready = 0
self._log_files = {} # 'class': log_file_obj
@@ -794,7 +799,7 @@ class MailList(MailCommandHandler, HTMLFormatter, Deliverer, ListAdmin,
self.CheckHTMLArchiveDir()
def Load(self, check_version = 1):
- if self._tmp_lock:
+ if self.__createlock_p:
self.Lock()
try:
file = open(os.path.join(self._full_path, 'config.db'), 'r')
@@ -1358,35 +1363,22 @@ class MailList(MailCommandHandler, HTMLFormatter, Deliverer, ListAdmin,
self.Save()
def Locked(self):
- try:
- return self._lock_file and 1
- except AttributeError:
- return 0
+ return self.__lock.locked()
def Lock(self):
- try:
- if self._lock_file:
- return
- except AttributeError:
- return
- ou = os.umask(0)
- try:
- self._lock_file = posixfile.open(
- os.path.join(mm_cfg.LOCK_DIR, '%s.lock' % self._internal_name),
- 'a+')
- finally:
- os.umask(ou)
- self._lock_file.lock('w|', 1)
+ self.__lock.lock()
def Unlock(self):
- if self.Locked():
- self._lock_file.lock('u')
- self._lock_file.close()
- self._lock_file = None
+ try:
+ self.__lock.unlock()
+ except LockFile.NotLockedError:
+ pass
def __repr__(self):
- if self.Locked(): status = " (locked)"
- else: status = ""
- return ("<%s.%s %s%s at %s>"
- % (self.__module__, self.__class__.__name__,
- `self._internal_name`, status, hex(id(self))[2:]))
+ if self.Locked():
+ status = " (locked)"
+ else:
+ status = ""
+ return ("<%s.%s %s%s at %s>" %
+ (self.__module__, self.__class__.__name__,
+ `self._internal_name`, status, hex(id(self))[2:]))