annotate Lib/lockfile.py @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents c2ff2163f0b7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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))