Fixed regression in file locking on some platforms.
Some platforms with os.name == 'posix' do not have the fcntl module, e.g. AppEngine. refs #19373.
This commit is contained in:
parent
8520e43e13
commit
61fdb8d487
|
@ -85,22 +85,14 @@ if os.name == 'nt':
|
||||||
overlapped = OVERLAPPED()
|
overlapped = OVERLAPPED()
|
||||||
ret = UnlockFileEx(hfile, 0, 0, 0xFFFF0000, byref(overlapped))
|
ret = UnlockFileEx(hfile, 0, 0, 0xFFFF0000, byref(overlapped))
|
||||||
return bool(ret)
|
return bool(ret)
|
||||||
|
else:
|
||||||
elif os.name == 'posix':
|
try:
|
||||||
import fcntl
|
import fcntl
|
||||||
LOCK_SH = fcntl.LOCK_SH # shared lock
|
LOCK_SH = fcntl.LOCK_SH # shared lock
|
||||||
LOCK_NB = fcntl.LOCK_NB # non-blocking
|
LOCK_NB = fcntl.LOCK_NB # non-blocking
|
||||||
LOCK_EX = fcntl.LOCK_EX
|
LOCK_EX = fcntl.LOCK_EX
|
||||||
|
except (ImportError, AttributeError):
|
||||||
def lock(f, flags):
|
# File locking is not supported.
|
||||||
ret = fcntl.flock(_fd(f), flags)
|
|
||||||
return (ret == 0)
|
|
||||||
|
|
||||||
def unlock(f):
|
|
||||||
ret = fcntl.flock(_fd(f), fcntl.LOCK_UN)
|
|
||||||
return (ret == 0)
|
|
||||||
|
|
||||||
else: # File locking is not supported.
|
|
||||||
LOCK_EX = LOCK_SH = LOCK_NB = 0
|
LOCK_EX = LOCK_SH = LOCK_NB = 0
|
||||||
|
|
||||||
# Dummy functions that don't do anything.
|
# Dummy functions that don't do anything.
|
||||||
|
@ -111,3 +103,11 @@ else: # File locking is not supported.
|
||||||
def unlock(f):
|
def unlock(f):
|
||||||
# File is unlocked
|
# File is unlocked
|
||||||
return True
|
return True
|
||||||
|
else:
|
||||||
|
def lock(f, flags):
|
||||||
|
ret = fcntl.flock(_fd(f), flags)
|
||||||
|
return (ret == 0)
|
||||||
|
|
||||||
|
def unlock(f):
|
||||||
|
ret = fcntl.flock(_fd(f), fcntl.LOCK_UN)
|
||||||
|
return (ret == 0)
|
||||||
|
|
Loading…
Reference in New Issue