4
The ZODB lock_file module provides support for creating file system
5
locks. These are locks that are implemented with lock files and
6
OS-provided locking facilities. To create a lock, instantiate a
7
LockFile object with a file name:
9
>>> import ZODB.lock_file
10
>>> lock = ZODB.lock_file.LockFile('lock')
12
If we try to lock the same name, we'll get a lock error and it will be logged:
14
>>> import ZODB.tests.loggingsupport
15
>>> handler = ZODB.tests.loggingsupport.InstalledHandler('ZODB.lock_file')
17
... ZODB.lock_file.LockFile('lock')
18
... except ZODB.lock_file.LockError:
19
... print "Can't lock file"
22
>>> for record in handler.records:
23
... print record.levelname, record.getMessage()
24
ERROR Error locking file lock; pid=UNKNOWN
26
To release the lock, use it's close method:
30
The lock file is not removed. It is left behind:
33
>>> os.path.exists('lock')
36
Of course, now that we've released the lock, we can created it again:
38
>>> lock = ZODB.lock_file.LockFile('lock')