Better closing of app

This commit is contained in:
deckensteuerung 2018-08-22 19:43:16 +02:00
parent 51e8263dbd
commit 3f34d88bbc
2 changed files with 24 additions and 10 deletions

View File

@ -17,10 +17,10 @@ kx, ky = np.meshgrid(np.fft.fftfreq(Nx,Lx/(Nx*2.0*np.pi)), np.fft.fftfreq(Ny,Ly/
ksq = kx*kx + ky*ky ksq = kx*kx + ky*ky
c = 0.0+(np.random.random((Ny,Nx))-0.5)*0.1 c = 0.0+(np.random.random((Ny,Nx))-0.5)*0.1
#eps=0.3 eps=0.3
#delta=0.0 delta=0.0
eps = 0.1 #eps = 0.1
delta = 1.0 #delta = 1.0
t = 0.0 t = 0.0
dt = 0.01 dt = 0.01
@ -49,6 +49,8 @@ while True:
i+= 1 i+= 1
ck=Eu*(ck+dt*(delta*np.fft.fft2(np.fft.ifft2(ck)**2)-np.fft.fft2(np.fft.ifft2(ck)**3))) ck=Eu*(ck+dt*(delta*np.fft.fft2(np.fft.ifft2(ck)**2)-np.fft.fft2(np.fft.ifft2(ck)**3)))
c=np.fft.ifft2(ck) c=np.fft.ifft2(ck)
eps = 0.1+0.2*np.cos(i/10000)
delta = np.sin(i/10000)
if(i % plotEveryNth == 0): if(i % plotEveryNth == 0):
myc = c.real myc = c.real
myc = (myc-np.min(myc))/(np.max(myc)-np.min(myc)) myc = (myc-np.min(myc))/(np.max(myc)-np.min(myc))

24
main.py
View File

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