#26152: django.setup() hangs django if ever used in a module that's imported by 
an
app
--------------------------------------+------------------------------------
     Reporter:  hjwp                  |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  Documentation         |                  Version:  1.9
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by hjwp):

 Just been digging into this.  And I am not an experienced coder of
 multithreaded code, so I probably shouldn't be allowed.

 Here's the current code:

 {{{
         # populate() might be called by two threads in parallel on servers
         # that create threads before initializing the WSGI callable.
         with self._lock:
             if self.ready:
                 return

             # app_config should be pristine, otherwise the code below
 won't
             # guarantee that the order matches the order in
 INSTALLED_APPS.
             if self.app_configs:
                 raise RuntimeError("populate() isn't reentrant")

             # [...] rest of populate code
             self.ready = True

 }}}

 So switching _lock to being a threading.RLock will have the desired effect
 of raising the "populate isn't reentrant" exception that's already been
 defined, if populate is ever called recursively by the same thread.

 I'm not sure I understand the code though.  Under what circumstances, with
 the current threading.Lock(), would we expect the RuntimeError to be
 encountered?

--
Ticket URL: <https://code.djangoproject.com/ticket/26152#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" 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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/062.a1c85771b59e31f1d5588545a420c434%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to