I have a python script that needs to be running before even starting flask app. it keeps checking database and if there is an entry it will take data, process it and return results to database. Now I need to deploy it on server but I can't understand how it can be done. There is a similar question while trying provided solution as following
@app.route('/')
def run_script():
file = open(r'/path/to/your/file.py', 'r').read()
return exec(file)
it only runs that file and doesn't return index.html
file. I have also tried to call run_script
inside index
function where is returns index.html
file, but still it only runs script, rather than returning index.html
. The main purpose to use this script is to save memory as it creates an instance of deep learning model and if I create this instance with every user call it consumes too much memory. script code can be found in this gist and quest_df = flask_qg.gen_qa(input_text)
creates that model. Can someone help me that how can I run this file on server?
source https://stackoverflow.com/questions/69781384/run-python-script-at-the-start-before-starting-flask-app
Comments
Post a Comment