global variables get undefined on re-run of flask app,I have 3 files,
api.py
import trainerapp = Flask(__name__)@app.route('/start', methods=['POST'])def apifunc(id): result = trainer.consume(id) return jsonify(result)if __name__ == '__main__': app.run(debug=True, port=LISTEN_PORT, threaded=True, use_reloader=False)
trainer.py
from utilities import function1def consume(id) value = function1(agg1) ... some codes... return value
utilities.py
aggregate = 30def function1(agg1): global aggregate ... some codes... print(aggregate)
when we run the app for the first time and hit the end point "/start", it picks the global variable "aggregate" value, it works,
buton 2nd hit, it throws error,
ERROR:api:500 Internal Server Error: name 'aggregate' is not defined
but when I stop and re-start the app and hit end point it works. Not sure why that's happening.