baselines = base_lines() baselines.get_base_lines(blocking_queue) #this is where application code goes #for example: print baselines.readings emokit.interrupt() emokit = emokit_interaction() #make the blocking_queue take 1 second of data from the headset #the headset runs at 128hz blocking_queue = blocking_queue(128) eeg_draw = eeg_draw() list = [0 for x in range(16)] if __name__ == "__main__": try: t = gevent.spawn(emokit.headset.setup) gevent.sleep(0) gevent.joinall([ #create a producer thread with target=generate_data gevent.spawn(generate_data,emokit,blocking_queue), #create a consumer thread with target=grab_some_data gevent.spawn(grab_some_data,emokit,blocking_queue) ])
#this example demonstrates how to use the blocking_queue in #a threaded environment #it also demonstrates the way that because of the 'threshold' #some data points will be lost in a more or less continuous data set. #by Sam Findler import threading from blocking_queue import blocking_queue #import blocking_queue data structure bq = blocking_queue(100) #blocking_queue is set with a threshold, which is the number of elements in #the queue before it will accept a get, it is also the #max number of elements in the blocking_queue def getter(s): "attempts to get a list of elements from blocking_queue s" a = s.get() #get returns [] if it could not get data yet, hence the loop while(a == []): a = s.get() print str(a) + "\n" return a def putter(s,p): "attempts to put an element p on blocking queue s" s.put(p) return def run1(s): "put 1000 items on the queue"