Ending an entire experiment after a set time (60 minutes)

Good afternoon,
I am running a task where I would like participant’s to complete as many “rounds” (loops) in a 60 minute period.
Then I would like the whole task to End, regardless of what routine they are in at the time. How can I set a clock to end an entire Experiment not just a single routine=

This is the code I have tried so far:

In the first routine I added to Begin Experiment:
myClock = core.Clock()

After the instructions, in the first routine I added to EndRoutine:
(so the time taken to read the instructions does not contribute to the 60 minutes of the task.

Then in the final routine within the loop of my testing block I added:
if myClock.getTime() > 300:
trials_2.finished = True

Please note trials_2.finished is the name of my loop.
And I chose 300 seconds to test the clock feature in 5 minutes to save myself time.

Any advice would be greatly appreciated :slight_smile:

Hi @Jessica_Talbot,

What kind of issues are you experiencing: experiment ending too early or too late, Error message?
The code you’ve shared looks like it should work, so it might be an issue with code location.

If you are resetting the clock in the loop, then the loop will never be able to end. Try adding myClock.reset() to EndRoutine of the instructions, since that is outside of your loop.

This code looks good, is it located in Each Frame or End Routine? As long as it is in one of those locations it should behave properly. If it is in Before Experiment or Start Experiment it will only get checked once at the start and the loop will never end.

If your experiment is more complex, with multiple nested loops, you may need additional code to tell all loops to end.

Hope that helps,

1 Like