0

I have code that reads using stdout constantly in a while loop, and I want to display 1 of either 2 images on the tkinter gui based on this stdout. The stdout data comes in as an array that is used to decide which of the 2 images the python gui will display. However, I cannot figure out how to get threading to work in this case. Here is the basic code without threading:


from subprocess import Popen, PIPE
print ("Opening...")
p = Popen ("C:\Program Files\Demo.exe", stdout=PIPE)

arr2 = []
arr3 = []
start = 0
dtct = 0
away = 0
chk = 0
sensitivity = 15
print ("Reading...")
while 1:
    line = p.stdout.readline()
    if not line: break
    if line.find(':')!= -1 and len(line) > 4:
                    time = line.split(",")[1]
                    Ta= line.split(",")[2]
                    arr1 = [float(n) for n in line.split(',')[3:67]]
                    delta = [i - j for i, j in zip(arr1,arr2)]
                    deltarnd = [ round(elem, 2) for elem in delta ]
                    for index, item in enumerate(deltarnd):
                            if item > 3:
                                    dtct = dtct +1
                            if item < -3:
                                    away = away +1
                    if (dtct > sensitivity) and chk == 0:
                            print "hand detected"
                            chk = 1
                    if (away > sensitivity) and chk == 1:
                            print "hand moved away"
                            chk = 0
                    dtct=0
                    away=0
                    arr3=arr2
                    arr2=arr1
print ("EOP")
a p
  • 1
  • 1
  • 2
    Threading is not mandatory here. Have a look at `createfilehandler`. See this answer: http://stackoverflow.com/a/3348777/428236 – FabienAndre Sep 25 '12 at 15:12
  • thanks for the tip! working on it now – a p Sep 25 '12 at 17:07
  • This is my first python program and I am not the best at programming. Do you know of any examples I can look at? – a p Sep 25 '12 at 17:27

0 Answers0