I am writing a python program that is supposed to make a GPS measurement every second while at the same time conducting some other measurements. I eventually tend to do this using two threads, and now I'm trying to write the GPS-thread.
I wrote a version of it according to the method make measurement - wait - reiterate:
navigator = GPS()
data = []
def avg(xlist):
a=sum(xlist)/len(xlist)
return a
x=[]
y=[]
for i in range(20):
data.append(navigator.GetData())
x.append(data[i]['x'])
y.append(data[i]['y'])
print "x: ",x[i],", y: ",y[i]
time.sleep(1)
navigator.CloseThread()
del navigator
xavg=avg(x)
yavg=avg(y)
I suppose if I write the program in this manner it will 1. Be a CPU hog 2. Not make measurements at even seconds. What should I do?