Loop Should End After 5 Minutes, But Experiment Forcefully Terminates Instead

Hello.

I am creating a “word puzzle task”, where each routine contains a word quiz with a 1-minute time limit. If participants fail to complete the word quizzes within a total of 5 minutes, the loop should be forced to end, and the experiment should proceed to the next routine (instructions).

The 1-minute time limit per routine works correctly, and each quiz automatically moves to the next one as expected. However, when the 5-minute limit is reached, the experiment does not move to the next routine. Instead, the entire experiment forcefully terminates.

What could be causing this issue?

I would really appreciate any help.
Thank you in advance!

Below is the Python code I have set up.


Begin Experiment

globalClock = core.Clock()
max_total_time = 300.0

Begin Routine

timer = core.Clock()
max_time = 60.0

Each Frame

if timer.getTime() > max_time:
    continueRoutine = False  

if globalClock.getTime() > max_total_time:
    continueRoutine = False
    trials.finished = True

What error message do you get in the Runner?

The following error occurs:

raise KeyError(key) from err  
KeyError: 1  
################ Experiment ended with exit code 1 [pid:47812] #################  

“The number in KeyError: 1” keeps changing (e.g., 0, 1, 2, 3, …).

Please could you show more of the error? It should be possible to identify which line of code is raising the key error.

Thank you for your response! Here is the full error message.


Generating PsychoPy script…

Alert 4405: Editable textbox component textbox and keyboard component key_resp in the same routine may compete for keypresses
For more info see https://docs.psychopy.org/alerts/4405.htmlAlert 4405: Editable textbox component textbox_2 and keyboard component key_resp_2 in the same routine may compete for keypresses
For more info see https://docs.psychopy.org/alerts/4405.html########## Running: C:\Users\joywo\Desktop\program\WFCT\WFCT_lastrun.py ###########
36.7430 EXP Imported oneloop/one.xlsx as conditions, 16 conditions, 1 params
36.7653 INFO Loaded monitor calibration from [‘2025_03_08 18:44’]
36.8051 EXP Imported oneloop/one.xlsx as conditions, 16 conditions, 1 params
36.8152 INFO Loaded monitor calibration from [‘2025_03_08 18:44’]
36.8839 EXP Imported oneloop/one.xlsx as conditions, 16 conditions, 1 params
48.0912 WARNING Could not get image from: https://secure.gravatar.com/avatar/53c942e9ef3fa94165056fa525658007?s=80&d=identicon, using blank image instead.
48.0994 WARNING Could not get image from: https://secure.gravatar.com/avatar/53c942e9ef3fa94165056fa525658007?s=80&d=identicon, using blank image instead.
Traceback (most recent call last):
4.8749 WARNING Font Manager failed to load file C:\Users\joywo\AppData\Local\Microsoft\Windows\Fonts\NanumBatang.ttf
File “D:\Psychopy\lib\site-packages\pandas\core\indexes\range.py”, line 413, in get_loc
return self._range.index(new_key)
ValueError: 1 is not in range

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “C:\Users\joywo\Desktop\program\WFCT\WFCT_lastrun.py”, line 1887, in
run(
File “C:\Users\joywo\Desktop\program\WFCT\WFCT_lastrun.py”, line 1440, in run
oneloop.saveAsExcel(filename + ‘.xlsx’, sheetName=‘oneloop’,
File “D:\Psychopy\lib\site-packages\psychopy\data\base.py”, line 324, in saveAsExcel
dataArray = self._createOutputArray(stimOut=stimOut,
File “D:\Psychopy\lib\site-packages\psychopy\data\trial.py”, line 1419, in _createOutputArray
tmpData = dataAnal[thisDataOut][stimN]
File “D:\Psychopy\lib\site-packages\pandas\core\series.py”, line 1121, in getitem
return self._get_value(key)
File “D:\Psychopy\lib\site-packages\pandas\core\series.py”, line 1237, in _get_value
loc = self.index.get_loc(label)
File “D:\Psychopy\lib\site-packages\pandas\core\indexes\range.py”, line 415, in get_loc
raise KeyError(key) from err
KeyError: 1
4.8753 WARNING Font Manager failed to load file C:\Users\joywo\AppData\Local\Microsoft\Windows\Fonts\NanumGulim.ttf

12.9660 WARNING launchHubServer: If using the iohub mouse or eyetracker devices, fullScr should be True.
1.4592 WARNING Monitor specification not found. Creating a temporary one…
ioHub Server Process Completed With Code: 0
################ Experiment ended with exit code 1 [pid:29588] #################