I didn't try this but might work. You can create a second manage.py called
for example manage2.py file with following contents:
#!/usr/bin/env python
from django.core.management import execute_manager
import imp
try:
imp.find_module('alternative_settings') # Assumed to be in the same
directory.
except ImportError:
import sys
sys.stderr.write("Error: Can't find the file 'settings.py' in the
directory containing %r. It appears you've customized things.\nYou'll have
to run django-admin.py, passing it your settings module.\n" % __file__)
sys.exit(1)
import alternative_settings
if __name__ == "__main__":
execute_manager(alternative_settings)
Then create an alternative_settings.py file, all the same but don't make
heavy calculations there.
2011/8/19 Boaz Leskes <[email protected]>
> Hi,
>
> I have some computationally intensive initialization logic that
> should
> run when a new process is started up by the web server. Following
> advice on the web, I've imported the module with the initialization
> code from settings.py, which works perfectly as advertised. However,
> it has one side effect which is very cumbersome - the code runs with
> every manage command as well. Every syncdb (and migration as we use
> South) takes forever. This is a problem during deployment.
>
> What's the best way to run initialization code only when it is
> executed under a server? (runserver & mod_wsgi) - is there any way to
> tell that a manage command is active at the moment and what it is? I
> could then not run the code for anything but runserver.
>
> Thanks,
> Boaz
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.