I've got a Flask app running under Apache using mod_wsgi. The app needs to do do some initialisation, including setting some top-level variables that need to be accessible inside the request handlers, before it receives any requests. At the moment this initialisation code is just top-level statements in app.py
before the request handling methods:
from flask import Flask, Response, request
<other app imports>
APP = Flask(__name__)
# initialisation code
@APP.route(<URL for request #1>)
def request_handler_1():
# request handler code
@APP.route(<URL for request #2>)
def request_handler_2():
# request handler code
The application's wsgi file looks like this:
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/myapp")
from myapp.app import APP as application
application.secret_key = <secret key>
I've noticed that the initialisation code is not called until the first request is received. How can I made the initialisation code be executed when the app is loaded by mod_wsgi, before any requests are received?
app.py
and setting up logging. – D. Joe