Hello,
My experiment hasn’t been ending properly. Once finished, the green Run button is greyed out until I hit Stop. After configuring all of my libraries properly and installing the 1.84.01 (see here for my previous issues), I am still having problems. I have, however, narrowed it down.
I mostly built my experiment from the builder, but added a few things in the coder. Here is the block that is giving me trouble:
# ------Prepare to start Routine "Q"-------
t = 0
QClock.reset() # clock
frameN = -1
continueRoutine = True
# update component parameters for each repeat
current_question.setText(question)
go_on_Q = event.BuilderKeyResponse()
wavName = wavDirName+'/'+expInfo['participant']+'.'+expInfo['episode']+expInfo['condition']+'_'+str(Qnum)+'.wav'
record = microphone.AdvAudioCapture(name='record', filename=wavName, stereo=False)
# keep track of which components have finished
QComponents = [current_question, go_on_Q, t_text, record]
for thisComponent in QComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# -------Start Routine "Q"-------
while continueRoutine:
# get current time
t = QClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *current_question* updates
if t >= 0.0 and current_question.status == NOT_STARTED:
# keep track of start time/frame for later
current_question.tStart = t
current_question.frameNStart = frameN # exact frame index
current_question.setAutoDraw(True)
# *go_on_Q* updates
if t >= 0.0 and go_on_Q.status == NOT_STARTED:
# keep track of start time/frame for later
go_on_Q.tStart = t
go_on_Q.frameNStart = frameN # exact frame index
go_on_Q.status = STARTED
# keyboard checking is just starting
win.callOnFlip(go_on_Q.clock.reset) # t=0 on next screen flip
event.clearEvents(eventType='keyboard')
if go_on_Q.status == STARTED:
theseKeys = event.getKeys(keyList=['space'])
# check for quit:
if "escape" in theseKeys:
endExpNow = True
if len(theseKeys) > 0: # at least one key was pressed
go_on_Q.keys = theseKeys[-1] # just the last key pressed
go_on_Q.rt = go_on_Q.clock.getTime()
# a response ends the routine
continueRoutine = False
# *t_text* updates
if t >= 0.0 and t_text.status == NOT_STARTED:
# keep track of start time/frame for later
t_text.tStart = t
t_text.frameNStart = frameN # exact frame index
t_text.setAutoDraw(True)
# *record* updates
if t >= 0.0 and record.status == NOT_STARTED:
# keep track of start time/frame for later
record.tStart = t
record.frameNStart = frameN # exact frame index
record.status = STARTED
record.record(sec=100, block=False) # start the recording thread
if record.status == STARTED and not record.recorder.running:
record.status = FINISHED
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in QComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# -------Ending Routine "Q"-------
for thisComponent in QComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# check responses
if go_on_Q.keys in ['', [], None]: # No response was made
go_on_Q.keys=None
questions.addData('go_on_Q.keys',go_on_Q.keys)
if go_on_Q.keys != None: # we had a response
questions.addData('go_on_Q.rt', go_on_Q.rt)
# record stop & responses
record.stop() # sometimes helpful
Qnum = int(Qnum) + 1
if not record.savedFile:
record.savedFile = None
# store data for questions (TrialHandler)
questions.addData('record.filename', record.savedFile)
# the Routine "Q" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# completed 1 repeats of 'questions'
Once the experiment is over, it does not properly close out. I have narrow it down to this line:
record.record(sec=100, block=False) # start the recording thread
The experiment doesn’t end because it appears to be waiting for the duration to finish. For example, if I change sec=1, the experiment ends very quickly. However, I thought that if you call record.stop() then it would end the recording early. I am recording verbal response to questions here and the answers vary in durations, thus I choose sec=100 as a long duration knowing that I could end it early.
Any idea why this isn’t ending properly? I have also attached my full presentation script as well.
Thanks you,
Dustin
TRW_comp.py (33.9 KB)

It could also be added in a code component with some careful surgery. It was my first foray into audio programming, so I’m sure there are ways it could be improved. If you want to use it, let me know if anything I’m about to say doesn’t make sense to you.