#26152: django.setup() hangs django if ever used in a module that's imported by 
an
app
-------------------------------+--------------------
     Reporter:  hjwp           |      Owner:  nobody
         Type:  Uncategorized  |     Status:  new
    Component:  Uncategorized  |    Version:  1.9
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+--------------------
 The docs suggest using django.setup() for any script that needs to be run
 standalone:

 https://docs.djangoproject.com/en/1.9/topics/settings/#calling-django-
 setup-is-required-for-standalone-django-usage

 But this causes problems if a standalone script also contains some code
 that is imported by a regular django app.

 Here's a minimal repro:

 
https://github.com/hjwp/recursive_django_setup_bug_minimal_repro/commit/15208c126796980cbe238ffe168d8b1bafaace26

 if foo.py contains django.setup(), and myapp.models.py tries to import
 from foo.py, that now causes a hang such that no manage.py call will ever
 complete.  ouch!

 The solution/workaround is to put any calls to django.setup() inside a

 {{{
 if __name__ == '__main__':
     import django
     django.setup()
 }}}

 I gather that fixing django.setup() / apps.populate() to make it reentrant
 is hard.  So this could be a quick documentation fix instead?

 cf #18251, a more complex version of this bug I think, which is in fact
 quite simple to run into...

--
Ticket URL: <https://code.djangoproject.com/ticket/26152>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/047.701369560af35265af60da5295a5c009%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to