On Tue, Jul 12, 2016 at 3:25 AM Aymeric Augustin <
[email protected]> wrote:
> def _populate(self):
> with self._lock:
> if self._populated:
> return
> # … populate …
> self._populated = True
>
Depending on how frequently the code is called, it might be worthwhile to
check self._populated prior to obtaining the lock.
def _populate(self):
if self._populated:
return
with self._lock:
if self._populated:
return
# ... populate ...
self._populated = True
This way the only time you're waiting on the lock is when you actually need
to be waiting on the lock, i.e. while another thread is populating.
-Aron
--
You received this message because you are subscribed to the Google Groups
"Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/CADu1%3D220Hmiqq-MeH3gSRtW9C2eqmS7A3jZ%2B25dSiPPcsa%3DzVw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.