How to make the duration of a routine fixed?

Hi,

My experiment has a part for participants to solve math problems. There is a loop to display each problem and each of them is self-paced. As participants may vary on the time they spend on these problems, I want to make the duration of this routine fixed (e.g., 5minutes). Can someone help me with this? Many thanks!

Best
Xiaotong

To make it more clear, here’s the screen shot and the code in this routine.

begine experiment

inputText = ""

begin routine

shift_flag = False

each frame

n= len(theseKeys)
i = 0
while i < n:

    if theseKeys[i] == 'return' and len(inputText) > 0:
        continueRoutine = False
        break

    elif theseKeys[i] == 'backspace':
        inputText = inputText[:-1]  
        i = i + 1

    elif theseKeys[i] == 'space':
        inputText += ' '
        i = i + 1

    elif theseKeys[i] in ['lshift', 'rshift']:
        shift_flag = True
        i = i + 1
    elif theseKeys[i] == 'period':
        inputText = inputText + "."
        i = i + 1

    else:
        if len(theseKeys[i]) == 1:
            if shift_flag:
                inputText += chr( ord(theseKeys[i]) - ord(' '))
                shift_flag = False
            else:
                inputText += theseKeys[i]

        i = i + 1

end routine

thisExp.addData('inputText', inputText)
inputText=""

I want the duration of this routine to be a fixed 5 minutes. Actually I don’t know whether it’s correct to call it ‘routine’. I mean I want to controll the time of runing these trials as 5 minutes, no matter whether all the trials are finished or not. (note, participantes are self-paced on each trial. They’ll decide how much time they spend on each question.)

Could someone help me with this? Thank you.