[Zodb-checkins] SVN: ZODB/branches/jim-zeo-blob/src/ZODB/ Added lock_file test.

Jim Fulton jim at zope.com
Wed May 16 13:36:44 EDT 2007


Log message for revision 75810:
  Added lock_file test.
  

Changed:
  A   ZODB/branches/jim-zeo-blob/src/ZODB/lock_file.txt
  A   ZODB/branches/jim-zeo-blob/src/ZODB/tests/test_lock_file.py
  D   ZODB/branches/jim-zeo-blob/src/ZODB/tests/testwinlock.py

-=-
Added: ZODB/branches/jim-zeo-blob/src/ZODB/lock_file.txt
===================================================================
--- ZODB/branches/jim-zeo-blob/src/ZODB/lock_file.txt	                        (rev 0)
+++ ZODB/branches/jim-zeo-blob/src/ZODB/lock_file.txt	2007-05-16 17:36:43 UTC (rev 75810)
@@ -0,0 +1,54 @@
+Lock file support
+=================
+
+Obviously, this should move out of the ZODB package. :/
+
+The ZODB lock_file module provides support for creating file system
+locks.  These are locks that are implemented with lock files and
+OS-provided locking facilities.  To create a lock, instantiate a
+LockFile object with a file name:
+
+    >>> import ZODB.lock_file
+    >>> lock = ZODB.lock_file.LockFile('lock')
+
+The lock contains the pid of the creating process:
+
+    >>> import os
+    >>> open('lock').read().strip() == str(os.getpid())
+    True
+
+If we try to lock the same name, we'll get a lock error:
+
+    >>> try:
+    ...     ZODB.lock_file.LockFile('lock')
+    ... except ZODB.lock_file.LockError:
+    ...     print "Can't lock file"
+    Can't lock file
+
+To release the lock, use it's close method:
+
+    >>> lock.close()
+
+The lock file is automatically removed:
+
+    >>> os.path.exists('lock')
+    False
+
+Of course, now that we've released the lock, we can created it again:
+
+    >>> lock = ZODB.lock_file.LockFile('lock')
+    >>> lock.close()
+    >>> os.path.exists('lock')
+    False
+
+It's OK if the file exists, say because it wasn't cleaned up properly:
+
+    >>> _ = open('lock', 'w')
+    >>> os.path.exists('lock')
+    True
+    >>> lock = ZODB.lock_file.LockFile('lock')
+    >>> lock.close()
+    >>> os.path.exists('lock')
+    False
+
+Of course, it's a bad idea to put precious data into a lock file.


Property changes on: ZODB/branches/jim-zeo-blob/src/ZODB/lock_file.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Copied: ZODB/branches/jim-zeo-blob/src/ZODB/tests/test_lock_file.py (from rev 75806, ZODB/branches/jim-zeo-blob/src/ZODB/tests/testwinlock.py)
===================================================================
--- ZODB/branches/jim-zeo-blob/src/ZODB/tests/test_lock_file.py	                        (rev 0)
+++ ZODB/branches/jim-zeo-blob/src/ZODB/tests/test_lock_file.py	2007-05-16 17:36:43 UTC (rev 75810)
@@ -0,0 +1,22 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+import os, sys, unittest
+from zope.testing import doctest
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTest(doctest.DocFileSuite(os.path.join('..', 'lock_file.txt')))
+    if sys.platform == 'win32':
+        suite.addTest(doctest.DocFileSuite(os.path.join('..', 'winlock.txt')))
+    return suite

Deleted: ZODB/branches/jim-zeo-blob/src/ZODB/tests/testwinlock.py
===================================================================
--- ZODB/branches/jim-zeo-blob/src/ZODB/tests/testwinlock.py	2007-05-16 17:36:41 UTC (rev 75809)
+++ ZODB/branches/jim-zeo-blob/src/ZODB/tests/testwinlock.py	2007-05-16 17:36:43 UTC (rev 75810)
@@ -1,22 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-import os, sys, unittest
-from zope.testing import doctest
-
-def test_suite():
-    if sys.platform == 'win32':
-        return doctest.DocFileSuite(os.path.join('..', 'winlock.txt'))
-    else:
-        return unittest.TestSuite()
-



More information about the Zodb-checkins mailing list