# Delay in ending a routine

**URL:** <https://discourse.psychopy.org/t/delay-in-ending-a-routine/9766>\
**Category:** Builder\
**Created:** [November 6, 2019, 11:14am UTC](https://discourse.psychopy.org/t/delay-in-ending-a-routine/9766 "2019-11-06T11:14:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GioP](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/giop/32/5851_2.png) [@GioP](https://discourse.psychopy.org/u/GioP)\
**Post date:** [November 6, 2019, 11:14am UTC](https://discourse.psychopy.org/t/delay-in-ending-a-routine/9766/1 "2019-11-06T11:14:21Z")

</div>

Dear all,

I am having problems in ending a routine. I am using version 1.85.3.

In my experiment there are two blocks. If the participant fails at the first one, she/he will not be able to access Block 2, but will be directly sent at the end message. If she/he does not fail, the experiment will go to Block 2.

To inform them about their eligibility in taking part at Block2 there is a message (Routine `eligible_t1`). They have to press any button to make the routine ends.

```auto
if score_training1 >=1:
    msg_eligible = "You can take part at pt. 2"
    msg_eligible_color = [0.5,0.9,0]
elif score_training1 == 0:
    msg_eligible = "You can not take part at pt. 2"
    msg_eligible_color=[1,0,0]
    not_eligible1 = 1

```

If they are not eligible a value gets assigned to them: `not_eligible = 1`.

All the following routines - except for the last one in which I thank the participant - have this code (that I tried to put at Each Frame and Begin Routine as well):

```auto
if not_eligible1 == 1:
    continueRoutine = False

```

What happens however, is that the message `You can not take part at pt. 2` will keep to be displayed for quite some time (ca. 5 seconds after the press) and it is not even possible to force the exit with the Esc button. After this seconds, the experiment goes to the last slide, as expected.

As you can see from the Image I am uploading, there is a huge distance between the routine `eligible_t1` and the end of the experiment - it didn´t even fit in the screenshot. It is at the end of `repeat_trainin_loop1b`, once the loop is over.

 ![Screenshot_2019-11-06_12-08-52](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/e/2/e25d8c7fd274a332a29680c962e308e734a788ec.png)

Thanks 🙂

* * *

**UPDATE**. A less complex case, likely linked to the previous one.

The same thing is happening in another context as well - this is `pre_isntructions_b`:

 ![tre](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/a/b/ab58b63b35c1f693f4689355a2ad9cf6fde45569.png)

Here participants are asked if they want to read the instructions again or not, in Each Frame of `code_pre_instr`:

```auto
if resp_pre_instr.corr:
    pre_instr_value=1
    repeat_training_loop_b.finished=True
    continueRoutine = False

```

If they press a specific key on the keyboard to say “_no_”, the instructions should be skipped and the experiment should immediately go to what´s after `repeat_training_loop_b` (that is, `break_tr1_tr2`). If they press the key for “_yes_”, the experiment should enter in the `repeat_training_sub` loop, where the instructions are repeated.

Both loops work pretty fine, with one problem, as the one described before. If they press “no”, before the experiment skips the loop the question remains on the display for 20sec, like it is getting stuck somewhere.

One thing that might be important to mention is that the instructions in `instructions_b` contain 5 images of ca. 350 kB each (jpeg). But they shouldn´t be even loaded if I exit the routine with `continueRoutine = False`.

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [November 6, 2019, 9:43pm UTC](https://discourse.psychopy.org/t/delay-in-ending-a-routine/9766/2 "2019-11-06T21:43:32Z")

</div>

> [@GioP](#):
>
> All the following routines - except for the last one in which I thank the participant - have this code (that I tried to put at Each Frame and Begin Routine as well)

It should only be necessary in the “Begin routine” tab. But you also need to add this:

```
your_loop_name.finished = True

```

Otherwise, the loops will keep running to completion, even if all of the routines within them terminate immediately. This might take some time, even though nothing visible is happening.

---

<div class="post-metadata">

**Author:** ![GioP](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/giop/32/5851_2.png) [@GioP](https://discourse.psychopy.org/u/GioP)\
**Post date:** [November 7, 2019, 10:19am UTC](https://discourse.psychopy.org/t/delay-in-ending-a-routine/9766/3 "2019-11-07T10:19:02Z")

</div>

> [@Michael](#):
>
> your\_loop\_name.finished = True

Thank you very much! Now it seems to work perfectly 🙂
