I am trying to design a visual stimulus for experiments in my lab. The stimulus should stop when the user presses a key. The entire experiment is timing sensitive and so I cannot run the key check serially.
The code that I wrote looks like this.
class designStim:
'''
This is class to hold functions designing the stimulus. There
are other functions in this class but the only one that is
called is the following.
'''
def deisgnStart(self)
#This function returns a dictionary variable containing
#the raw stimulus
class dispStim(threading.Thread):
def __init__(self,stimdata,q):
threading.Thread.__init__(self)
#*Assign the other data from stimdata to self*
def run(self):
#Code to run the stimulus
class checkKbdAbort(threading.Thread):
def __init__(self,q):
threading.Thread.__init__(self)
def run(self):
#Code to check for keyboard key press. In case of key press,
#use the queue to abort dispStim*
if __name__ == '__main__':
a=designStim('test')
stimdata=a.designStart()
q=Queue()
thread1=dispStim(stimdata,q)
thread2=checkKbdAbort(q)
thread1.start()
thread2.start()
This code works when I run serially which leads me to believe that my display scripts are correct. However, when I run the code in this form, the two threads are not run in parallel. thread1
executes and then thread2
runs. During the thread1
run, the stimulus does not display. Is there a mistake I am making during the class initialization/call?