psychopy.org | Reference | Downloads | Github

Can't start a new thread

Hi All

I am new to Psychopy and looking for some help with a ’ Can’t start new thread’ issue.

My experiment runs a loop that goes through 3 routines where a voice sound (angry (SA), neutral (SN) or happy (SH)) and a video clip is played at the same time for 5 seconds. Each of the routines is interspersed with a baseline which is a silent 10 seconds with a blurred cartoon (BA, BN & BH). The loop goes round 8 times so each condition (angry, neutral and happy) is run 8 times each with a corresponding baseline following it. I have a spreadsheet with the conditions laid out as below

SA_No SN_No SH_No BA_No BN_No BH_No
SA1 SN1 SH1 BA1 BN1 BH1
SA2 SN2 SH2 BA2 BN2 BH2
SA3 SN3 SH3 BA3 BN3 BH3
SA4 SN4 SH4 BA4 BN4 BH4
SA5 SN5 SH5 BA5 BN5 BH5
SA6 SN6 SH6 BA6 BN6 BH6
SA7 SN7 SH7 BA7 BN7 BH7
SA8 SN8 SH8 BA8 BN8 BH8

My problem is that the loop runs fine until the transition from SA8 to BA8. The error message is as follows:

Line 428 depth 0,0
Line 148 Self.load.movie (self.filename)
Line 211 raise IOE (emsg% (estr, filename,msg)
IO error: caught exception ‘can’t start new thread’ while loading file ‘b2.mov’

I don’t understand why it goes through this transition for 7 runs of the loop before it stops. I am obviously not that experience but I have checked through the code and I still cannot really see what’s gone wrong. Any help much appreciated. I have copied parts of the code that I think relevant below:

Lines 316 - 485

# set up handler to look after randomisation of conditions etc
trials = data.TrialHandler(nReps=1, method='sequential', 
    extraInfo=expInfo, originPath=-1,
    trialList=data.importConditions('final_s1&s2_E.xlsx'),
    seed=None, name='trials')
thisExp.addLoop(trials)  # add the loop to the experiment
thisTrial = trials.trialList[0]  # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb = thisTrial.rgb)
if thisTrial != None:
    for paramName in thisTrial.keys():
        exec(paramName + '= thisTrial.' + paramName)

for thisTrial in trials:
    currentLoop = trials
    # abbreviate parameter names if possible (e.g. rgb = thisTrial.rgb)
    if thisTrial != None:
        for paramName in thisTrial.keys():
            exec(paramName + '= thisTrial.' + paramName)
    
    # ------Prepare to start Routine "sound_A"-------
    t = 0
    sound_AClock.reset()  # clock
    frameN = -1
    continueRoutine = True
    routineTimer.add(5.000000)
    # update component parameters for each repeat
    sound_1.setSound('angry_chain_1.wav', secs=5)
    movie_7 = visual.MovieStim(
        win=win, name='movie_7',units='cm', 
        filename='video30.mov',
        ori=0, pos=[0, 0], opacity=1,
        size=[48,28],
        depth=-1.0,
        )
    text_10.setText(SA_No)
    # keep track of which components have finished
    sound_AComponents = [sound_1, movie_7, text_10]
    for thisComponent in sound_AComponents:
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
    
    # -------Start Routine "sound_A"-------
    while continueRoutine and routineTimer.getTime() > 0:
        # get current time
        t = sound_AClock.getTime()
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        # start/stop sound_1
        if t >= 0.0 and sound_1.status == NOT_STARTED:
            # keep track of start time/frame for later
            sound_1.tStart = t
            sound_1.frameNStart = frameN  # exact frame index
            sound_1.play()  # start the sound (it finishes automatically)
        frameRemains = 0.0 + 5- win.monitorFramePeriod * 0.75  # most of one frame period left
        if sound_1.status == STARTED and t >= frameRemains:
            sound_1.stop()  # stop the sound (if longer than duration)
        
        # *movie_7* updates
        if t >= 0.0 and movie_7.status == NOT_STARTED:
            # keep track of start time/frame for later
            movie_7.tStart = t
            movie_7.frameNStart = frameN  # exact frame index
            movie_7.setAutoDraw(True)
        frameRemains = 0.0 + 5- win.monitorFramePeriod * 0.75  # most of one frame period left
        if movie_7.status == STARTED and t >= frameRemains:
            movie_7.setAutoDraw(False)
        
        # *text_10* updates
        if t >= 0.0 and text_10.status == NOT_STARTED:
            # keep track of start time/frame for later
            text_10.tStart = t
            text_10.frameNStart = frameN  # exact frame index
            text_10.setAutoDraw(True)
        frameRemains = 0.0 + 5- win.monitorFramePeriod * 0.75  # most of one frame period left
        if text_10.status == STARTED and t >= frameRemains:
            text_10.setAutoDraw(False)
        
        # 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 sound_AComponents:
            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 "sound_A"-------
    for thisComponent in sound_AComponents:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    sound_1.stop()  # ensure sound has stopped at end of routine
    
    # ------Prepare to start Routine "basline_A"-------
    t = 0
    basline_AClock.reset()  # clock
    frameN = -1
    continueRoutine = True
    routineTimer.add(10.000000)
    # update component parameters for each repeat
    movie = visual.MovieStim(
        win=win, name='movie',units='cm', 
        filename='b2.mov',
        ori=0, pos=[0, 0], opacity=1,
        size=[48,28],
        depth=0.0,
        )
    text_6.setText(BA_No)
    # keep track of which components have finished
    basline_AComponents = [movie, text_6]
    for thisComponent in basline_AComponents:
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
    
    # -------Start Routine "basline_A"-------
    while continueRoutine and routineTimer.getTime() > 0:
        # get current time
        t = basline_AClock.getTime()
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        
        # *movie* updates
        if t >= 0.0 and movie.status == NOT_STARTED:
            # keep track of start time/frame for later
            movie.tStart = t
            movie.frameNStart = frameN  # exact frame index
            movie.setAutoDraw(True)
        frameRemains = 0.0 + 10- win.monitorFramePeriod * 0.75  # most of one frame period left
        if movie.status == STARTED and t >= frameRemains:
            movie.setAutoDraw(False)
        
        # *text_6* updates
        if t >= 0.0 and text_6.status == NOT_STARTED:
            # keep track of start time/frame for later
            text_6.tStart = t
            text_6.frameNStart = frameN  # exact frame index
            text_6.setAutoDraw(True)
        frameRemains = 0.0 + 10- win.monitorFramePeriod * 0.75  # most of one frame period left
        if text_6.status == STARTED and t >= frameRemains:
            text_6.setAutoDraw(False)
        
        # 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 basline_AComponents:
            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 "basline_A"-------
    for thisComponent in basline_AComponents:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)