Anyone interested in using the non-blocking (i.e. `locks.LOCKS_NB`)
requires a valid return value to know if they have successfully acquired
the lock.
I believe the correct implementation should be the following:
{{{
diff --git a/django/core/files/locks.py b/django/core/files/locks.py
index c46b00b905..4938347ea7 100644
--- a/django/core/files/locks.py
+++ b/django/core/files/locks.py
@@ -107,9 +107,15 @@ else:
return True
else:
def lock(f, flags):
- ret = fcntl.flock(_fd(f), flags)
- return ret == 0
+ try:
+ fcntl.flock(_fd(f), flags)
+ return True
+ except OSError:
+ return False
def unlock(f):
- ret = fcntl.flock(_fd(f), fcntl.LOCK_UN)
- return ret == 0
+ try:
+ fcntl.flock(_fd(f), fcntl.LOCK_UN)
+ return True
+ except OSError:
+ return False
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31989>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* has_patch: 1 => 0
* component: Core (Other) => File uploads/storage
* stage: Unreviewed => Accepted
Comment:
Thanks for the ticket. Would you like to prepare a pull request? (tests
are also required).
--
Ticket URL: <https://code.djangoproject.com/ticket/31989#comment:1>
* owner: nobody => Hasan Ramezani
* status: new => assigned
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/13410 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/31989#comment:2>
* needs_better_patch: 0 => 1
* needs_docs: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/31989#comment:3>
* needs_better_patch: 1 => 0
* needs_docs: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/31989#comment:4>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/31989#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"7be6a6a4d665061e8bc6a741b16ff92353f5d19e" 7be6a6a4]:
{{{
#!CommitTicketReference repository=""
revision="7be6a6a4d665061e8bc6a741b16ff92353f5d19e"
Fixed #31989 -- Fixed return value of
django.core.files.locks.lock()/unlock() on POSIX systems.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31989#comment:6>