Code chunk keeps evaluating although the routine has ended, why?

Win10 Pro
Python 3.8.10
PsychoPy v2023.2.3
Standard Standalone?

I have a simple experiment. In a loop with 12 sequential reps, I first present an image stimulus the display of which is terminated upon a button press, followed by moving dots in a separate routine, then the next round of the loop starts. When the loop is done, I present one final new image stimulus. Then the experiment ends. In the image stimulus routine within the loop, I specify custom code, which evaluates the current trial number and prints it to the runner i=trials.thisN print(f"Running trial number {i}"). This code is in “Begin routine”. In “End routine” I collect the reaction time and print it to the runner with rt = key_resp.rt print(f"Reaction time was: {rt}"). For the final new image stimulus, there is no code, here I want nothing evaluated or printed. However, when I run the experiment, I also get the trial number for this new final trial and the associated reaction time. Why is this so? I thought the code snippet is limited to the routine for which it is defined. Why is there this spill over?

Is the new image in a loop?

I suspect that you are seeing the RT from the last image in the loop. If your next trial isn’t in a loop then you can force the data onto the next row using thisExp.nextEntry()