From 7be80f72da851f43db6755c6bd4560a2b5b2d613 Mon Sep 17 00:00:00 2001 From: Mike Olund Date: Fri, 17 Mar 2017 09:36:51 -0700 Subject: [PATCH] Only run wsgi initialization once --- wsgi.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/wsgi.py b/wsgi.py index 85adbd7b..821721af 100644 --- a/wsgi.py +++ b/wsgi.py @@ -16,9 +16,14 @@ if not os.environ.get('OPENSHIFT_BUILD_NAMESPACE', False): os.environ.setdefault("DJANGO_SETTINGS_MODULE", "edivorce.settings.local") else: os.environ.setdefault("DJANGO_SETTINGS_MODULE", "edivorce.settings.openshift") - # compress the static assets - # execute_from_command_line(['manage.py', 'compress', '--force']) - # load the Question fixture - # execute_from_command_line(['manage.py', 'loaddata', '/opt/app-root/src/edivorce/fixtures/Question.json']) + + if os.environ.get('POD_INIT_COMPLETE', "") != "True": + # gunicorn starts multiple threads and runs wsgi.py once for each thread. We only want + # these commands to run ONCE. + os.environ["POD_INIT_COMPLETE"] = "True" + # compress the static assets + execute_from_command_line(['manage.py', 'compress', '--force']) + # load the Question fixture + execute_from_command_line(['manage.py', 'loaddata', '/opt/app-root/src/edivorce/fixtures/Question.json']) application = get_wsgi_application()