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

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.

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

1 Like

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():
timer(5.0, setready).start()