Raise RuntimeError(“Cannot close stream, not opened yet.”)

I got the answer here:

The solution is to:

  1. Remove $stim_dur from the duration of the movie (make it blank)
  2. Add the following code to Each Frame
if t > stim_dur:
     continueRoutine = False