[Checkins] SVN: zc.lockfile/trunk/ Fixed: when there was lock contention, the pid in the lock file was lost.

jim cvs-admin at zope.org
Tue Nov 20 21:43:07 UTC 2012


Log message for revision 128368:
  Fixed: when there was lock contention, the pid in the lock file was lost.

Changed:
  U   zc.lockfile/trunk/CHANGES.txt
  U   zc.lockfile/trunk/src/zc/lockfile/README.txt
  U   zc.lockfile/trunk/src/zc/lockfile/__init__.py
  U   zc.lockfile/trunk/src/zc/lockfile/tests.py

-=-
Modified: zc.lockfile/trunk/CHANGES.txt
===================================================================
--- zc.lockfile/trunk/CHANGES.txt	2012-11-20 21:40:16 UTC (rev 128367)
+++ zc.lockfile/trunk/CHANGES.txt	2012-11-20 21:43:06 UTC (rev 128368)
@@ -1,9 +1,15 @@
 Change History
 ***************
 
-1.0.1 (unreleased)
+1.0.1 (2012-11-30)
 ==================
 
+- Fixed: when there was lock contention, the pid in the lock file was
+  lost.'
+
+  Thanks to Daniel Moisset reporting the problem and providing a fix
+  with tests.
+
 - Added test extra to declare test dependency on ``zope.testing``.
 
 - Using Python's ``doctest`` module instead of depreacted

Modified: zc.lockfile/trunk/src/zc/lockfile/README.txt
===================================================================
--- zc.lockfile/trunk/src/zc/lockfile/README.txt	2012-11-20 21:40:16 UTC (rev 128367)
+++ zc.lockfile/trunk/src/zc/lockfile/README.txt	2012-11-20 21:43:06 UTC (rev 128368)
@@ -19,9 +19,9 @@
     ...     print "Can't lock file"
     Can't lock file
 
-    >>> for record in handler.records:
+    >>> for record in handler.records: # doctest: +ELLIPSIS
     ...     print record.levelname, record.getMessage()
-    ERROR Error locking file lock; pid=UNKNOWN
+    ERROR Error locking file lock; pid=...
 
 To release the lock, use it's close method:
 

Modified: zc.lockfile/trunk/src/zc/lockfile/__init__.py
===================================================================
--- zc.lockfile/trunk/src/zc/lockfile/__init__.py	2012-11-20 21:40:16 UTC (rev 128367)
+++ zc.lockfile/trunk/src/zc/lockfile/__init__.py	2012-11-20 21:43:06 UTC (rev 128368)
@@ -72,7 +72,7 @@
         self._path = path
         # XXX this overwrites the pid info.  Should probably be r+.
         # Need a test.
-        fp = open(path, 'w+')
+        fp = open(path, 'a+')
 
         try:
             _lock_file(fp)

Modified: zc.lockfile/trunk/src/zc/lockfile/tests.py
===================================================================
--- zc.lockfile/trunk/src/zc/lockfile/tests.py	2012-11-20 21:40:16 UTC (rev 128367)
+++ zc.lockfile/trunk/src/zc/lockfile/tests.py	2012-11-20 21:43:06 UTC (rev 128368)
@@ -50,6 +50,24 @@
     >>> os.remove('f.lock')
     """
 
+def pid_in_lockfile():
+    r"""
+    >>> import os, zc.lockfile
+    >>> pid = os.getpid()
+    >>> lock = zc.lockfile.LockFile("f.lock")
+    >>> open("f.lock").read().strip() == str(pid)
+    True
+
+    Make sure that locking twice does not overwrite the old pid:
+    
+    >>> lock = zc.lockfile.LockFile("f.lock")
+    Traceback (most recent call last):
+      ...
+    LockError: Couldn't lock 'f.lock'
+    >>> open("f.lock").read().strip() == str(pid)
+    True
+    """
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(doctest.DocFileSuite(



More information about the checkins mailing list