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
If you want to run a bunch of command (as a regular Py app) after flask run, use a multi processing library (for example multiprocessing), In this solution you can have an API/Web application beside of a system program.
import flask
from flask import request, jsonify,make_response
import time
import multiprocessing
app = flask.Flask('__name__')
def API(Conf):
print('In API selction')
app.run(host='0.0.0.0', port=1337,)
if __name__ == "__main__":
config = {"Something":"SomethingElese"}
p = multiprocessing.Process(target=API, args=(Conf,))
p.start()
#time.sleep(3)
print('After Flask run')
Note: above code just a sample/idea. Maybe have some error. (But I used this solution in production area and it's fine.)
P.S. : (in my perspective) the problem of this solution: more difficulty in debugging section.