mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
django manage.py load settings before we launch every worker. This
change remove it from loaded modules on reload. While we are here we remove any django module preloaded so we can upgrade django version to on HUP. fix issue #197.
This commit is contained in:
parent
9cec1229fa
commit
f1d5f26dfa
@ -62,13 +62,18 @@ class DjangoApplication(Application):
|
|||||||
|
|
||||||
def no_settings(self, path, import_error=False):
|
def no_settings(self, path, import_error=False):
|
||||||
if import_error:
|
if import_error:
|
||||||
error = "Error: Can't find the settings in your PYTHONPATH"
|
error = "Error: Can't find '%s' in your PYTHONPATH.\n" % path
|
||||||
else:
|
else:
|
||||||
error = "Settings file '%s' not found in current folder.\n" % path
|
error = "Settings file '%s' not found in current folder.\n" % path
|
||||||
sys.stderr.write(error)
|
sys.stderr.write(error)
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
def activate_translation(self):
|
||||||
|
from django.conf import settings
|
||||||
|
from django.utils import translation
|
||||||
|
translation.activate(settings.LANGUAGE_CODE)
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
""" Validate models. This also ensures that all models are
|
""" Validate models. This also ensures that all models are
|
||||||
imported in case of import-time side effects."""
|
imported in case of import-time side effects."""
|
||||||
@ -90,13 +95,15 @@ class DjangoApplication(Application):
|
|||||||
def load(self):
|
def load(self):
|
||||||
from django.conf import ENVIRONMENT_VARIABLE
|
from django.conf import ENVIRONMENT_VARIABLE
|
||||||
from django.core.handlers.wsgi import WSGIHandler
|
from django.core.handlers.wsgi import WSGIHandler
|
||||||
|
|
||||||
os.environ[ENVIRONMENT_VARIABLE] = self.settings_modname
|
os.environ[ENVIRONMENT_VARIABLE] = self.settings_modname
|
||||||
# setup environ
|
# setup environ
|
||||||
self.setup_environ()
|
self.setup_environ()
|
||||||
self.validate()
|
self.validate()
|
||||||
|
self.activate_translation()
|
||||||
return WSGIHandler()
|
return WSGIHandler()
|
||||||
|
|
||||||
class DjangoApplicationCommand(Application):
|
class DjangoApplicationCommand(DjangoApplication):
|
||||||
|
|
||||||
def __init__(self, options, admin_media_path):
|
def __init__(self, options, admin_media_path):
|
||||||
self.usage = None
|
self.usage = None
|
||||||
@ -105,6 +112,9 @@ class DjangoApplicationCommand(Application):
|
|||||||
self.options = options
|
self.options = options
|
||||||
self.admin_media_path = admin_media_path
|
self.admin_media_path = admin_media_path
|
||||||
self.callable = None
|
self.callable = None
|
||||||
|
self.settings_modname = os.environ[ENVIRONMENT_VARIABLE]
|
||||||
|
self.project_path = os.getcwd()
|
||||||
|
|
||||||
self.do_load_config()
|
self.do_load_config()
|
||||||
|
|
||||||
def load_config(self):
|
def load_config(self):
|
||||||
@ -139,9 +149,29 @@ class DjangoApplicationCommand(Application):
|
|||||||
if k.lower() in self.cfg.settings and v is not None:
|
if k.lower() in self.cfg.settings and v is not None:
|
||||||
self.cfg.set(k.lower(), v)
|
self.cfg.set(k.lower(), v)
|
||||||
|
|
||||||
|
def setup_environ(self):
|
||||||
|
for modname in sys.modules.keys():
|
||||||
|
if modname.startswith('django') or \
|
||||||
|
'settings' in modname.split('.'):
|
||||||
|
del sys.modules[modname]
|
||||||
|
|
||||||
|
# add the project path to sys.path
|
||||||
|
sys.path.insert(0, self.project_path)
|
||||||
|
sys.path.append(os.path.join(self.project_path, os.pardir))
|
||||||
|
|
||||||
|
|
||||||
|
super(DjangoApplicationCommand, self).setup_environ()
|
||||||
|
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
|
# setup environ
|
||||||
|
self.setup_environ()
|
||||||
|
self.validate()
|
||||||
|
self.activate_translation()
|
||||||
|
|
||||||
from django.core.servers.basehttp import AdminMediaHandler, WSGIServerException
|
from django.core.servers.basehttp import AdminMediaHandler, WSGIServerException
|
||||||
from django.core.handlers.wsgi import WSGIHandler
|
from django.core.handlers.wsgi import WSGIHandler
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return AdminMediaHandler(WSGIHandler(), self.admin_media_path)
|
return AdminMediaHandler(WSGIHandler(), self.admin_media_path)
|
||||||
except WSGIServerException, e:
|
except WSGIServerException, e:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user