mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
Module to lock open files using fcntl()
This commit is contained in:
parent
f13285271f
commit
19806f4ce2
2 changed files with 30 additions and 0 deletions
15
Lib/lib-old/lockfile.py
Normal file
15
Lib/lib-old/lockfile.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import struct, fcntl, FCNTL
|
||||
|
||||
def writelock(f):
|
||||
_lock(f, FCNTL.F_WRLCK)
|
||||
|
||||
def readlock(f):
|
||||
_lock(f, FCNTL.F_RDLCK)
|
||||
|
||||
def unlock(f):
|
||||
_lock(f, FCNTL.F_UNLCK)
|
||||
|
||||
def _lock(f, op):
|
||||
dummy = fcntl.fcntl(f.fileno(), FCNTL.F_SETLKW,
|
||||
struct.pack('2h8l', op,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0))
|
||||
15
Lib/lockfile.py
Normal file
15
Lib/lockfile.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import struct, fcntl, FCNTL
|
||||
|
||||
def writelock(f):
|
||||
_lock(f, FCNTL.F_WRLCK)
|
||||
|
||||
def readlock(f):
|
||||
_lock(f, FCNTL.F_RDLCK)
|
||||
|
||||
def unlock(f):
|
||||
_lock(f, FCNTL.F_UNLCK)
|
||||
|
||||
def _lock(f, op):
|
||||
dummy = fcntl.fcntl(f.fileno(), FCNTL.F_SETLKW,
|
||||
struct.pack('2h8l', op,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0))
|
||||
Loading…
Add table
Add a link
Reference in a new issue