summaryrefslogtreecommitdiff
path: root/Mailman/LockFile.py
diff options
context:
space:
mode:
authorBarry Warsaw2007-08-01 17:05:06 -0400
committerBarry Warsaw2007-08-01 17:05:06 -0400
commitb2ce38ca3bf73010794860e969f6006ce632f151 (patch)
treef084f9dc60b97d9dda960854f0b3d42fb7de5f03 /Mailman/LockFile.py
parentf8a6c46455a409125dcc0fcace7d7116898b0319 (diff)
downloadmailman-b2ce38ca3bf73010794860e969f6006ce632f151.tar.gz
mailman-b2ce38ca3bf73010794860e969f6006ce632f151.tar.zst
mailman-b2ce38ca3bf73010794860e969f6006ce632f151.zip
Diffstat (limited to 'Mailman/LockFile.py')
-rw-r--r--Mailman/LockFile.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/Mailman/LockFile.py b/Mailman/LockFile.py
index d83cef7e2..33008e92b 100644
--- a/Mailman/LockFile.py
+++ b/Mailman/LockFile.py
@@ -59,12 +59,13 @@ import errno
import random
import socket
import logging
+import datetime
import traceback
# Units are floating-point seconds.
-DEFAULT_LOCK_LIFETIME = 15
+DEFAULT_LOCK_LIFETIME = datetime.timedelta(seconds=15)
# Allowable a bit of clock skew
-CLOCK_SLOP = 10
+CLOCK_SLOP = datetime.timedelta(seconds=10)
# This is appropriate for Mailman, but you may want to change this if you're
# using this code outside Mailman.
log = logging.getLogger('mailman.locks')
@@ -95,8 +96,8 @@ class LockFile:
Create the resource lock using lockfile as the global lock file. Each
process laying claim to this resource lock will create their own
temporary lock files based on the path specified by lockfile.
- Optional lifetime is the number of seconds the process expects to hold
- the lock.
+ Optional lifetime is a timedelta specifying the number of seconds the
+ process expects to hold the lock.
set_lifetime(lifetime):
Set a new lock lifetime. This takes affect the next time the file is
@@ -155,7 +156,7 @@ class LockFile:
self._owned = True
def __repr__(self):
- return '<LockFile %s: %s [%s: %ssec] pid=%s>' % (
+ return '<LockFile %s: %s [%s: %s] pid=%s>' % (
id(self), self._lockfile,
self.locked() and 'locked' or 'unlocked',
self._lifetime, os.getpid())
@@ -400,7 +401,8 @@ class LockFile:
return None
def _touch(self, filename=None):
- t = time.time() + self._lifetime
+ expiration_date = datetime.datetime.now() + self._lifetime
+ t = time.mktime(expiration_date.timetuple())
try:
# XXX We probably don't need to modify atime, but this is easier.
os.utime(filename or self._tmpfname, (t, t))