Mercurial > cpython-lru_cache-weakref
annotate Lib/lockfile.py @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | c2ff2163f0b7 |
| children |
| rev | line source |
|---|---|
|
1604
c2ff2163f0b7
Module to lock open files using fcntl()
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 import struct, fcntl, FCNTL |
|
c2ff2163f0b7
Module to lock open files using fcntl()
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
c2ff2163f0b7
Module to lock open files using fcntl()
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 def writelock(f): |
|
c2ff2163f0b7
Module to lock open files using fcntl()
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 _lock(f, FCNTL.F_WRLCK) |
|
c2ff2163f0b7
Module to lock open files using fcntl()
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 |
|
c2ff2163f0b7
Module to lock open files using fcntl()
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 def readlock(f): |
|
c2ff2163f0b7
Module to lock open files using fcntl()
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 _lock(f, FCNTL.F_RDLCK) |
|
c2ff2163f0b7
Module to lock open files using fcntl()
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 |
|
c2ff2163f0b7
Module to lock open files using fcntl()
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 def unlock(f): |
|
c2ff2163f0b7
Module to lock open files using fcntl()
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 _lock(f, FCNTL.F_UNLCK) |
|
c2ff2163f0b7
Module to lock open files using fcntl()
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 |
|
c2ff2163f0b7
Module to lock open files using fcntl()
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 def _lock(f, op): |
|
c2ff2163f0b7
Module to lock open files using fcntl()
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 dummy = fcntl.fcntl(f.fileno(), FCNTL.F_SETLKW, |
|
c2ff2163f0b7
Module to lock open files using fcntl()
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 struct.pack('2h8l', op, |
|
c2ff2163f0b7
Module to lock open files using fcntl()
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 0, 0, 0, 0, 0, 0, 0, 0, 0)) |
