# Is It Safe to Use sleep in tag event script within a UDT parameter

**URL:** <https://forum.inductiveautomation.com/t/is-it-safe-to-use-sleep-in-tag-event-script-within-a-udt-parameter/34376>\
**Category:** Ignition\
**Created:** [May 2, 2020, 6:20pm UTC](https://forum.inductiveautomation.com/t/is-it-safe-to-use-sleep-in-tag-event-script-within-a-udt-parameter/34376 "2020-05-02T18:20:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![archana.kachru](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@archana.kachru](https://forum.inductiveautomation.com/u/archana.kachru)\
**Post date:** [May 2, 2020, 6:20pm UTC](https://forum.inductiveautomation.com/t/is-it-safe-to-use-sleep-in-tag-event-script-within-a-udt-parameter/34376/1 "2020-05-02T18:20:23Z")

</div>

Is it safe to use sleep function in the tag evnt script?

i have a time seconds parameter within the UDT and after 5 seconds, i am setting another tag inside the same UDT to 1.

I need to introduce a delay without having to create a counter logic. The manual is not clear on whether it is safe to run the following code in the tag event script.

The tag where this script is running is an expression tag getting the seconds.  
the script is written on value change

from time import sleep  
sleep (5)  
system.tag.write(ready, 1)  
after 5 seconds , it sets the ready flag to 1.

I have tried invoke later, Timer , but they are not working.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 3, 2020, 11:31am UTC](https://forum.inductiveautomation.com/t/is-it-safe-to-use-sleep-in-tag-event-script-within-a-udt-parameter/34376/2 "2020-05-03T11:31:46Z")

</div>

It is not safe to use sleep (of any kind) outside a dedicated thread (invokeAsynchronous).

---

<div class="post-metadata">

**Author:** ![archana.kachru](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@archana.kachru](https://forum.inductiveautomation.com/u/archana.kachru)\
**Post date:** [May 3, 2020, 7:10pm UTC](https://forum.inductiveautomation.com/t/is-it-safe-to-use-sleep-in-tag-event-script-within-a-udt-parameter/34376/3 "2020-05-03T19:10:01Z")

</div>

thank you, after i posted this question, i read your response about single thread operation… so i looked if i can get the timer function to work. i finally got it working.  
can i use the Timer option instead of the sleep ? I have used the following logic in the tag script. is this safe.  
from threading import Timer  
def setready():  
system.tag.write(tagname,1)  
timer(5.0, setready).start()
