From 7affda9c98749b497835a8ab0ad627fd97b8612f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Sat, 17 Feb 2024 16:36:43 +0100 Subject: [PATCH] moved the updater out of a seperate function the worked as a multiprocess because the global var wasnt shared between the processes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ebbe Baß --- server/app.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/server/app.py b/server/app.py index 3cfc100..a127bd4 100644 --- a/server/app.py +++ b/server/app.py @@ -145,20 +145,16 @@ def mqtt_publisher(): artNet.close() sys.exit() -def update_tube_index(): - global TUBE_INDEX +if __name__ == "__main__": + flask_thread = Process(target=flask_api) + flask_thread.start() + publisher_thread = Process(target=mqtt_publisher) + publisher_thread.start() + # Tube index updater while True: cur = db.cursor() cur.execute("SELECT mac_address, universe, dmx_address FROM tubes") TUBE_INDEX = cur.fetchall() cur.close() print("Updated index: "+str(TUBE_INDEX)) - time.sleep(1) - -if __name__ == "__main__": - tube_index_updater_thread = Process(target=update_tube_index) - tube_index_updater_thread.start() - flask_thread = Process(target=flask_api) - flask_thread.start() - publisher_thread = Process(target=mqtt_publisher) - publisher_thread.start() + time.sleep(1) \ No newline at end of file