Hello Rich,

> On 01 Mar 2016, at 01:44, Rich Jones <[email protected]> wrote:
> 
> I think the interesting things to explore would be:
>  - Loading apps in parallel
>  - "Pre-loading" apps before app deployment, then loading that cached state 
> at runtime. I guess I'd need to know more about what it means to "load" an 
> app to see if that makes any sense at all.


As of Django 1.7, loading an app means:

1. importing its app config class (what the dotted Python path in 
INSTALLED_APPS points to; if INSTALLED_APPS points to a Python package, an app 
config is generated on the fly)
2. importing its models module, if there is one (determined from the app config)
3. running the ready() method of the app config

In practice Django does 1. for all apps, then 2. for all apps, then 3. for all 
apps.

If “load an app” confuses you, read it as “import an app” or “import Python 
modules comprising this app”. Really there isn’t much going on aside from 
importing a bunch of Python modules. Some datastructures are built dynamically 
but I’d be surprised if it took a measurable amount of the startup time.

As far as I can tell from the rest of the discussion, the result of 
django.setup() is already cached and reused anyway, but I thought I’d demystify 
things a bit!


> I imagine the former is probably more feasible. I understand the aversion to 
> non-determinism, but I think that shouldn't matter as long as there is a way 
> to define inter-app dependencies.


Non-deterministic software has this strange tendency to deterministically work 
on developers’ laptops and deterministically fail on production servers ;-)

More seriously, there are cases where importing a Django project works when app 
A is imported before app B but deadlocks when app B is imported before app A. 
Apps that attempt to perform auto-discovery on other apps (such as the admin, 
debug-toolbar, haystack, etc.) are especially prone to this. This isn’t a 
theoretical argument. We’ve had these bugs and I spent hundreds of hours 
refactoring the app-loading process to eliminate them.

Also it’s unclear to me how developers could be sure that they’ve defined all 
required inter-app dependencies.


Best regards,

-- 
Aymeric.

-- 
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/2114E152-2353-4A51-BDA3-E25C96D5F56A%40polytechnique.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to