Better closing of app
This commit is contained in:
24
main.py
24
main.py
@@ -6,6 +6,11 @@ import threading
|
||||
import json
|
||||
from bottle import route, run
|
||||
import time
|
||||
import sys
|
||||
import signal
|
||||
|
||||
running = True
|
||||
|
||||
if config.UseGui:
|
||||
import pygame
|
||||
|
||||
@@ -18,13 +23,14 @@ if config.UseGui:
|
||||
self.data = data
|
||||
|
||||
def run(self):
|
||||
global running
|
||||
sf = config.GuiScaleFactor
|
||||
screen = pygame.display.set_mode((sf*config.ScreenX, sf*config.ScreenY))
|
||||
pygame.display.set_caption("Pixelserver - GUI Vis")
|
||||
while True:
|
||||
while running:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
sys.exit(0)
|
||||
running = False
|
||||
screen.fill((0, 255, 0))
|
||||
for x in range(config.ScreenX):
|
||||
for y in range(config.ScreenY):
|
||||
@@ -49,7 +55,7 @@ class SerialWriter(threading.Thread):
|
||||
def run(self):
|
||||
should_connect = True
|
||||
ser = None
|
||||
while True:
|
||||
while running:
|
||||
try:
|
||||
if should_connect:
|
||||
ser = serial.Serial(config.Serial)
|
||||
@@ -72,7 +78,7 @@ class WatchDog(threading.Thread):
|
||||
self.check = check
|
||||
self.action = action
|
||||
def run(self):
|
||||
while True:
|
||||
while running:
|
||||
if self.check():
|
||||
self.action()
|
||||
time.sleep(1)
|
||||
@@ -119,7 +125,7 @@ class AppRunner(threading.Thread):
|
||||
self.app = subprocess.Popen(args, stdout=subprocess.PIPE, close_fds=True)
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
while running:
|
||||
with self.lock:
|
||||
if self.app == None or self.app.poll() != None:
|
||||
self.requestedApp = 0
|
||||
@@ -137,7 +143,10 @@ class AppRunner(threading.Thread):
|
||||
self.gui.setData(data)
|
||||
except:
|
||||
pass
|
||||
|
||||
self.watchdog.join()
|
||||
self.serial.join()
|
||||
if config.UseGui:
|
||||
self.gui.join()
|
||||
|
||||
runner = AppRunner()
|
||||
runner.start()
|
||||
@@ -172,4 +181,7 @@ def apps_running():
|
||||
i = runner.currentApp
|
||||
return config.Apps[i]["name"]
|
||||
|
||||
|
||||
run(host="localhost", port=8000)
|
||||
running = False
|
||||
runner.join()
|
Reference in New Issue
Block a user