fix the fix that fixed the fix

This commit is contained in:
Arti Zirk 2016-10-15 11:52:54 +02:00
parent f26ff29eef
commit 5aaccabc93
1 changed files with 14 additions and 14 deletions

28
main.py
View File

@ -119,16 +119,19 @@ html = """<!DOCTYPE html>
temps = deque(maxlen=10)
def stream(dev):
while True:
temperature = dev.readline().decode().strip().split()[0]
if not temperature:
continue
print("temperature", temperature)
temps.append(temperature)
arduino = None
def stream(dev):
with serial.Serial(ser_dev, timeout=1) as s:
global arduino
arduino = s
while True:
temperature = s.readline().decode().strip().split()
if not temperature:
continue
print("temperature", temperature)
temps.append(temperature[0])
def application(env, start_response):
@ -203,11 +206,8 @@ if __name__ == "__main__":
print("{} is not a valid tty device".format(ser_dev))
exit(1)
with serial.Serial(ser_dev, timeout=1) as s:
arduino = s
import threading
t = threading.Thread(target=stream, args=[s])
import threading
t = threading.Thread(target=stream, args=[ser_dev])
# classifying as a daemon, so they will die when the main dies
t.daemon = True