summaryrefslogtreecommitdiff
path: root/django/core/files/locks.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/core/files/locks.py')
-rw-r--r--django/core/files/locks.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/django/core/files/locks.py b/django/core/files/locks.py
index 212b51a73d..98a11551a7 100644
--- a/django/core/files/locks.py
+++ b/django/core/files/locks.py
@@ -40,20 +40,24 @@ try:
except (ImportError, AttributeError):
pass
+def fd(f):
+ """Get a filedescriptor from something which could be a file or an fd."""
+ return hasattr(f, 'fileno') and f.fileno() or f
+
if system_type == 'nt':
def lock(file, flags):
- hfile = win32file._get_osfhandle(file.fileno())
+ hfile = win32file._get_osfhandle(fd(file))
win32file.LockFileEx(hfile, flags, 0, -0x10000, __overlapped)
def unlock(file):
- hfile = win32file._get_osfhandle(file.fileno())
+ hfile = win32file._get_osfhandle(fd(file))
win32file.UnlockFileEx(hfile, 0, -0x10000, __overlapped)
elif system_type == 'posix':
def lock(file, flags):
- fcntl.flock(file.fileno(), flags)
+ fcntl.flock(fd(file), flags)
def unlock(file):
- fcntl.flock(file.fileno(), fcntl.LOCK_UN)
+ fcntl.flock(fd(file), fcntl.LOCK_UN)
else:
# File locking is not supported.
LOCK_EX = LOCK_SH = LOCK_NB = None