Create the app once (and ensure safely done)
Also uses a context manager for the app context to ensure that it gets pushed and popped when finished. Change-Id: Id78c73853429607e4607911b7a59313d38b0bcbe
This commit is contained in:
parent
dca186adcb
commit
618eafa549
14
ara/wsgi.py
14
ara/wsgi.py
|
@ -33,6 +33,7 @@
|
|||
import os
|
||||
import logging
|
||||
import six
|
||||
import threading
|
||||
|
||||
if (int(os.getenv('ARA_WSGI_USE_VIRTUALENV', 0)) == 1 and
|
||||
os.getenv('ARA_WSGI_VIRTUALENV_PATH')):
|
||||
|
@ -49,6 +50,8 @@ if (int(os.getenv('ARA_WSGI_USE_VIRTUALENV', 0)) == 1 and
|
|||
from ara.webapp import create_app # flake8: noqa
|
||||
from flask import current_app # flake8: noqa
|
||||
|
||||
app = None
|
||||
app_making_lock = threading.Lock()
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -58,13 +61,10 @@ def application(environ, start_response):
|
|||
else:
|
||||
if 'ANSIBLE_CONFIG' not in os.environ:
|
||||
log.warn('ANSIBLE_CONFIG environment variable not found.')
|
||||
|
||||
app = create_app()
|
||||
if not current_app:
|
||||
ctx = app.app_context()
|
||||
ctx.push()
|
||||
return app(environ, start_response)
|
||||
else:
|
||||
with app_making_lock:
|
||||
if app is None:
|
||||
app = create_app()
|
||||
with app.app_context():
|
||||
return current_app(environ, start_response)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue