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 encountered this same issue in a flask app of mine. I wanted to start a scheduler at app startup, which would kick off some jobs at regular intervals. Since I deploy my apps inside docker containers, what I ended up doing is adding an "health check" endpoint which just returns a 200, and in my dockerfile configured that endpoint:
HEALTHCHECK CMD curl --fail http://localhost:8080/alive || exit 1
The default behavior is to execute that command every 30s, and the first run conveniently kicks off my init() method. https://docs.docker.com/engine/reference/builder/#healthcheck