~sidnei/zope3/ztk-1.0a1

« back to all changes in this revision

Viewing changes to src/ZODB/lock_file.txt

  • Committer: Sidnei da Silva
  • Date: 2010-03-03 03:29:50 UTC
  • mfrom: (12.1.16 trunk)
  • Revision ID: sidnei.da.silva@canonical.com-20100303032950-duivfaoqsxaf9dgg
Merged newer-from-ztk [r=jkakar,bigkevmcd,free][qa=andreas][f=522474].

Update our monolithic Zope 3 tree to a kgs-based, generated,
monolithic Zope 3 tree built from eggs using the
collective.buildout.omelette recipe.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Lock file support
2
 
=================
3
 
 
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:
8
 
 
9
 
    >>> import ZODB.lock_file
10
 
    >>> lock = ZODB.lock_file.LockFile('lock')
11
 
 
12
 
If we try to lock the same name, we'll get a lock error and it will be logged:
13
 
 
14
 
    >>> import ZODB.tests.loggingsupport
15
 
    >>> handler = ZODB.tests.loggingsupport.InstalledHandler('ZODB.lock_file')
16
 
    >>> try:
17
 
    ...     ZODB.lock_file.LockFile('lock')
18
 
    ... except ZODB.lock_file.LockError:
19
 
    ...     print "Can't lock file"
20
 
    Can't lock file
21
 
 
22
 
    >>> for record in handler.records:
23
 
    ...     print record.levelname, record.getMessage()
24
 
    ERROR Error locking file lock; pid=UNKNOWN
25
 
 
26
 
To release the lock, use it's close method:
27
 
 
28
 
    >>> lock.close()
29
 
 
30
 
The lock file is not removed.  It is left behind:
31
 
 
32
 
    >>> import os
33
 
    >>> os.path.exists('lock')
34
 
    True
35
 
 
36
 
Of course, now that we've released the lock, we can created it again:
37
 
 
38
 
    >>> lock = ZODB.lock_file.LockFile('lock')
39
 
    >>> lock.close()