From 20fd01aca20c788bc687460b194fd69096221c6e Mon Sep 17 00:00:00 2001 From: Emiliano Vavassori Date: Wed, 4 Sep 2024 17:20:18 +0200 Subject: [PATCH] Test fixing setup gpio. --- webapp.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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()