moved the updater out of a seperate function the worked as a multiprocess because the global var wasnt shared between the processes

Signed-off-by: Ebbe Baß <ebbe.bass>
main
Ebbe Baß 2024-02-17 16:36:43 +01:00
parent 3ba023229d
commit 7affda9c98
1 changed files with 7 additions and 11 deletions

View File

@ -145,8 +145,12 @@ def mqtt_publisher():
artNet.close() artNet.close()
sys.exit() sys.exit()
def update_tube_index(): if __name__ == "__main__":
global TUBE_INDEX flask_thread = Process(target=flask_api)
flask_thread.start()
publisher_thread = Process(target=mqtt_publisher)
publisher_thread.start()
# Tube index updater
while True: while True:
cur = db.cursor() cur = db.cursor()
cur.execute("SELECT mac_address, universe, dmx_address FROM tubes") cur.execute("SELECT mac_address, universe, dmx_address FROM tubes")
@ -154,11 +158,3 @@ def update_tube_index():
cur.close() cur.close()
print("Updated index: "+str(TUBE_INDEX)) print("Updated index: "+str(TUBE_INDEX))
time.sleep(1) 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()