Last trial of routine stuck in an infinite loop despite code to proceed

Hi guys,
I have a code to run a task on PsychoPy (v2021.2.3) on Windows 10 Enterprise (version 20H2). In this task, the participant is shown a series of words. Some have to be heard (the computer says the word) and others have to be imagined. All the words are stored in an Excel file. When I run my code, everything goes normally, right up to the last word in the routine, which is ‘lamp’. However, once this last word is spoken by the computer, it repeats itself, ad infinitum , instead of finishing the routine and moving on to the next one. Here is the code (the part that messes up at least):

#!/usr/bin/env python2
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division
from psychopy import locale_setup, sound, gui, visual, core, data, event, logging
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
                                STOPPED, FINISHED, PRESSED, RELEASED, FOREVER)
import numpy as np  # whole numpy lib is available, prepend 'np.'
from numpy import (sin, cos, tan, log, log10, pi, average,
                   sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle
import os  # handy system and path functions
import sys  # to get file system encoding
import serial #to add library creating EEG triggers
import psychtoolbox as ptb

# Ensure that relative paths start from the same directory as this script
_thisDir = os.path.dirname(os.path.abspath(__file__))
os.chdir(_thisDir)

# Store info about the experiment session
expName = u'RM_EEG'  # from the Builder filename that created this script
expInfo = { u'Numero participant': u''}
dlg = gui.DlgFromDict(dictionary=expInfo, title=expName)
if dlg.OK == False:
    core.quit()  # user pressed cancel
expInfo['date'] = data.getDateStr()  # add a simple timestamp
expInfo['expName'] = expName

# Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc
filename = _thisDir + os.sep + u'data/%s_%s_%s' % (expInfo['Numero participant'], expName, expInfo['date'])

# An ExperimentHandler isn't essential but helps with data saving
thisExp = data.ExperimentHandler(name=expName, version='',
    extraInfo=expInfo, runtimeInfo=None,
    originPath=None,
    savePickle=True, saveWideText=True,
    dataFileName=filename)
# save a log file for detail verbose info
logFile = logging.LogFile(filename+'.log', level=logging.EXP)
logging.console.setLevel(logging.WARNING)  # this outputs to the screen, not a file

endExpNow = False  # flag for 'escape' or other condition => quit the exp

# Start Code - component code to be run before the window creation

# Create a window
win = visual.Window(fullscr=True, color='black')
win.mouseVisible = False    #added by MM to make the mouse cursor invisible during task

#Initialize serial port address to add triggers
#port = serial.Serial('COM4') #add baudrate info?
#Defined triggers (note that triggers for words presentation are defined in excel files)
trigFix = 250
trigKey = 252


#Initialize instruction component to change the screen frame
Clickonspace = visual.TextStim(win=win, name='Clickonspace',
    text='Cliquez sur espace pour continuer', 
    font='Arial',
    pos = [0,-0.85], height=.05, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=-1.0);

# Import general instruction for the listen task
Consigne_generale = visual.ImageStim(win, image='Consignes/consignegenerale_ecouter.png',pos = [0, 0.1], size=(1.8,1.8))

# show instruction' picture
Consigne_generale.draw()
Clickonspace.draw()
win.flip()

# press space to continue
event.waitKeys(keyList=['space'])



# Initialize components for Routine "trial"
trialClock = core.Clock()
Fixation = visual.ImageStim( win=win, name='Fixation',
    image=u'Consignes/Fixation.png', mask=None,
    ori=0, pos=(0, 0), size=(0.25, 0.45),
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=-1.0);
Mot = visual.TextStim(win=win, name='Mot',
    text=u'default text',
    font=u'Arial',
    pos=(0, 0), height=0.15, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1,
    depth=0.0);
ISI = visual.TextStim(win=win, name='ISI',
    text=u' ',
    font=u'Arial',
    pos=(0, 0), height=0.15, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1,
    depth=0.0);

#Fixation cross duration
fixDurMin = 1.25 #minimum = 1250ms
fixDurMax = 1.75 #maximum = 1750ms
#ISI duration
ISIDurMin = 1.6 #minimum = 1600ms
ISIDurMax = 2.0 #maximum = 2000ms

#Son parameters
Son = sound.Sound('A', secs=2.0, stereo=True, sampleRate=44000) 
Son.setVolume(1)

# Create some handy timers
globalClock = core.Clock()  # to track the time since experiment started
routineTimer = core.CountdownTimer()  # to track time remaining of each (non-slip) routine 

trials = data.TrialHandler(nReps=1, method='sequential', 
    extraInfo=expInfo, originPath=-1,
    trialList=data.importConditions('Mots_ENTENDRE_confidence1.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('{} = thisTrial[paramName]'.format(paramName)) #MM: change syntax to be compatible with psychopy3

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('{} = thisTrial[paramName]'.format(paramName)) #MM: change syntax to be compatible with psychopy3

    # ------Prepare to start Routine "trial"-------
    t = 0
    trialClock.reset()  # clock
    frameN = -1
    fixDur = round(np.random.uniform(fixDurMin, fixDurMax), 1) #randomized between minimum and maximum
    ISIDur = round(np.random.uniform(ISIDurMin, ISIDurMax), 1) #randomized between minimum and maximum
    trials.addData('fixation_duration', fixDur)
    trials.addData('ISI_duration', ISIDur)
    continueRoutine = True
    routineTimer.add(fixDur + 2.00000 + ISIDur)
    # update component parameters for each repeat
    Mot.setText(mot)
    Son.setSound(son, secs = 2.0)
    # keep track of which components have finished
    trialComponents = [Fixation, fixDur, Mot, Son, ISI, ISIDur, trigFix, trigMot]
    for thisComponent in trialComponents:
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
    
    # -------Start Routine "trial"-------
    while continueRoutine and routineTimer.getTime() > 0:
        # get current time
        t = trialClock.getTime()
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        
        # *Fixation* presentation
        if t >= 0.0 and Fixation.status == NOT_STARTED:
            Fixation.tStart = t
            Fixation.frameNStart = frameN  # exact frame index
            Fixation.setAutoDraw(True)
            #setup trigger for *Fixation* presentation
            #port.write([trigFix])
            #core.wait(0.005)
            #port.write([0x00])
        # most of one frame period left
        if Fixation.status == STARTED and t >= (fixDur):
            Fixation.setAutoDraw(False)
            
        
        # *Mot* updates
        if t >= fixDur and Mot.status == NOT_STARTED:
            # start Mot
            # keep track of start time/frame for later
            Mot.tStart = t
            Mot.frameNStart = frameN  # exact frame index
            Mot.setAutoDraw(True)
            #setup triggers for *Mot* presentation
            #port.write([trigMot])
            #core.wait(0.005)
            #port.write([0x00])
        frameRemains = (fixDur + 2.0) - win.monitorFramePeriod * 0.75
        # most of one frame period left
        if Mot.status == STARTED and t >= frameRemains:
            Mot.setAutoDraw(False)
        
        # *Son* updates
        if t >= fixDur and Son.status == NOT_STARTED:
            now = ptb.GetSecs() # define exact presentation time of *Son*
            # start Son
            #setup triggers for *Son* presentation
            # keep track of start time/frame for later
            Son.tStart = t
            Son.frameNStart = frameN  # exact frame index
            Son.play(when=now)  # start the sound just at the word presentation (it finishes automatically)
        # most of one frame period left
        frameRemains = (fixDur + 2.0) - win.monitorFramePeriod * 0.75
        if Son.status == STARTED and t >= frameRemains:
            Son.stop()  # stop the sound (if longer than duration)
        
        # *ITI* presentation
        if t >= frameRemains and ISI.status == NOT_STARTED:
            # keep track of start time/frame for later
            ISI.tStart = t
            ISI.frameNStart = frameN  # exact frame index
            ISI.setAutoDraw(True)
        frameRemains2 = frameRemains + ISIDur- win.monitorFramePeriod * 0.75
        # most of one frame period left
        if ISI.status == STARTED and t >= frameRemains2:
            ISI.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 trialComponents:
            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 "trial"-------
    for thisComponent in trialComponents:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    Son.stop()  # ensure sound has stopped at end of routine
    thisExp.nextEntry()

I thank you in advance for any answer you can provide !