My goal is to get arbitrary code to run after my Flask application is started. Here is what I\'ve got:
def run():
from webapp import app
app.run(debu
I just did (in a main.py executed with python main.py):
with app.app_context():
from module import some_code
some_code()
def run():
from webapp import app
app.run(debug=True, use_reloader=False)
This worked for me without the more comprehensive answers offered above. In my case some_code() is initializing a cache via flask_caching.Cache.
But it probably depends on what exactly some_code is doing...