Skip to content

Commit

Permalink
implement graceful shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
ototadana committed Jun 4, 2022
1 parent 2283da7 commit 519aafc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion gui.py
Expand Up @@ -24,6 +24,7 @@
class Info:
def __init__(self):
self.__state = {}
self.__is_active = True

def set_states(self, states):
self.__state = states
Expand All @@ -34,12 +35,18 @@ def get_states(self):
def get_state(self, name):
return self.__state.get(name, 0.0)

def is_active(self):
return self.__is_active

def stop(self):
self.__is_active = False


info = Info()


def receive_state():
while True:
while info.is_active():
time.sleep(1)
try:
info.set_states({"bat": random.random() * 100})
Expand Down Expand Up @@ -71,4 +78,5 @@ def receive_state():
window["sent"].update(msg)
window["recv"].update("ok")

info.stop()
window.close()

0 comments on commit 519aafc

Please sign in to comment.