# Randomize duration of a Routine in Builder

**URL:** <https://discourse.psychopy.org/t/randomize-duration-of-a-routine-in-builder/21436>\
**Category:** Builder\
**Created:** [March 18, 2021, 6:51am UTC](https://discourse.psychopy.org/t/randomize-duration-of-a-routine-in-builder/21436 "2021-03-18T06:51:02Z")\
**Posts on this page:** 1\
**Showing post:** 23

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [October 29, 2022, 7:20am UTC](https://discourse.psychopy.org/t/randomize-duration-of-a-routine-in-builder/21436/23 "2022-10-29T07:20:40Z")

</div>

In searching other similar posts I found a thread which suggests that it might be because the movie is buffering.

> [@Raise RuntimeError(“Cannot close stream, not opened yet.”)](https://discourse.psychopy.org/t/raise-runtimeerror-cannot-close-stream-not-opened-yet/30283/5):
>
> I found a solution in my experiment (thanks to some help from colleagues)! I had to change the duration of the videos in the Excel sheet to be a little longer than the actual video duration. I added two seconds, but you can probably play around with it in your experiment. We think this is necessary because the video takes some time to buffer and so you need to include that in your duration time. Hopefully this helps!

However, I also saw that you’ve seen that thread so here is my suggestion.

1. Remove $stim\_dur from the duration of the movie (make it blank)

2. Add the following code to Each Frame

```auto
if t > stim_dur:
     continueRoutine = False

```

---

_[View the full topic](https://discourse.psychopy.org/t/randomize-duration-of-a-routine-in-builder/21436)._
