diff --git a/webapp.py b/webapp.py index b76d57d..4db1891 100644 --- a/webapp.py +++ b/webapp.py @@ -3,8 +3,17 @@ from flask import Flask import led +import os -app = Flask(__name__) +class MyFlask(Flask): + + def run(self, host=None, port=None, debug=None, load_dotenv=True, **options): + if not self.debug or os.getenv("WERKZEUG_RUN_MAIN") == 'true': + with self.app_context(): + led.setup() + super(MyFlask, self).run(host=host, port=port, debug=debug, load_dotenv=load_dotenv, **options) + +app = MyFlask(__name__) @app.route('/') def index(): @@ -41,7 +50,4 @@ def lampeggia(): led.lampeggia() return "LED ha lampeggiato." -if __name__ == '__main__': - with app.app_context(): - led.setup() - app.run() +app.run()