Notes on order of execution of PsychoPy Builder components and code

One of the reasons why people have errors or unexpected / unintended behaviour in their experiments is because PsychoPy is executing the commands in their experiment in a different order from the order they expected. I thought, therefore, it might be useful to lay out my understanding of this order.

During this description I am using the term routine order to mean that the routines are executed in the order they appear in the experiment flow (left to right) and the components are executed in the order they appear in the routine (top to bottom).

  1. Before Experiment code components are executed in routine order – possibly at the same time that resources are downloaded.

  2. The experiment starts and the window changes to full screen.

  3. Begin Experiment code components are executed in routine order interleaved with the creation of other components. Constant component parameters are set at this point. Set every repeat and set every frame component parameters are set as None or undefined. The screen is blank during this period.

  4. Begin Routine code components are executed in routine order interleaved with setting set every repeat component parameters. Components with a start time of 0 are set to start and the window is flipped.

  5. Each Frame code components are executed in routine order interleaved with set every frame component parameters. When all each frame operations have been executed continueRoutine and component durations are checked and the window is flipped.

  6. End Routine code components are executed in routine order after all components have ended or continueRoutine = False.

  7. End Experiment code components are executed in routine order after the final routine in the experiment flow has ended.

  8. The computer returns to normal view from full screen. Data is saved. Online this is not completed until the green barred thank you for your patience message appears.

  9. Online, if there is a completed URL, this will be opened in the same tab after OK has been clicked in the thank you for your patience message.

Please post corrections below. One recommendation from this is that unless you have a good reason to do otherwise, you should put your code components at the top of each routine so their Begin Routine code is executed before any each routine parameters are set.

1 Like