# What is the alternate for sleep()?

**URL:** <https://forum.inductiveautomation.com/t/what-is-the-alternate-for-sleep/111001>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 26, 2025, 11:11am UTC](https://forum.inductiveautomation.com/t/what-is-the-alternate-for-sleep/111001 "2025-09-26T11:11:58Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samkcr](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@Samkcr](https://forum.inductiveautomation.com/u/Samkcr)\
**Post date:** [September 26, 2025, 11:11am UTC](https://forum.inductiveautomation.com/t/what-is-the-alternate-for-sleep/111001/1 "2025-09-26T11:11:58Z")

</div>

Hi,

I found many threads in the forum for discussion on sleep(). Though I know this is not recommended to use, In my existing project there were several places sleep() has been used. So I want to get rid of this and looking for alternative. Which would be the best alternate approach?

I found that in the manual _“If a sleep() or While Loop function must be used, then they should be called from **[system.util.invokeAsynchronous](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-util/system-util-invokeAsynchronous)** to prevent blocking any other scripts.” Since_ **[system.util.invokeLater](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-util/system-util-invokeLater)** is not supported in Perspective.  
How to use this for my case?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 26, 2025, 11:20am UTC](https://forum.inductiveautomation.com/t/what-is-the-alternate-for-sleep/111001/2 "2025-09-26T11:20:27Z")

</div>

We don't know what your case is, so it's hard to say.

---

<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:** [September 26, 2025, 11:40am UTC](https://forum.inductiveautomation.com/t/what-is-the-alternate-for-sleep/111001/3 "2025-09-26T11:40:23Z")

</div>

Unlike Vision, Perspective is fairly tolerant of short sleeps (not in a loop). We need to know how it is used by your application to know how to help you, if even necessary.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 26, 2025, 12:12pm UTC](https://forum.inductiveautomation.com/t/what-is-the-alternate-for-sleep/111001/4 "2025-09-26T12:12:03Z")

</div>

Share the code that is using it, it would illuminate things for us.

---

<div class="post-metadata">

**Author:** ![Samkcr](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@Samkcr](https://forum.inductiveautomation.com/u/Samkcr)\
**Post date:** [September 26, 2025, 12:57pm UTC](https://forum.inductiveautomation.com/t/what-is-the-alternate-for-sleep/111001/5 "2025-09-26T12:57:32Z")

</div>

We are using the scripts in UI on multiple event scripts and transform scripts like example

```python
def runAction(self):
    import time
    self.session.custom.Anim = False
    self.getChild("root").getChild("Icon").props.style.transform = 'rotate(0deg)'
    time.sleep(1)

```

Similar usage in multiple places.. so I want to look for alternate if really causing the performance issue

the time also varies from 1 s to 10s

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 26, 2025, 1:33pm UTC](https://forum.inductiveautomation.com/t/what-is-the-alternate-for-sleep/111001/6 "2025-09-26T13:33:25Z")

</div>

huh ? Why ?

Wait, are you using sleep to set an animation time ?  
Like, you're resetting `.custom.Anim` to `false`, and the `transform` to `null` after the sleep ?

---

<div class="post-metadata">

**Author:** ![Steve\_Laubach](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steve_laubach/32/60900_2.png) [@Steve\_Laubach](https://forum.inductiveautomation.com/u/Steve_Laubach)\
**Post date:** [September 26, 2025, 1:36pm UTC](https://forum.inductiveautomation.com/t/what-is-the-alternate-for-sleep/111001/7 "2025-09-26T13:36:45Z")

</div>

You probably want to use CSS for this. What exactly are you trying to do?

If I’m understanding correctly, it looks like you’re running code to reset the rotation on something every second. that would definitely cause performance issues to do it that way.

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [September 26, 2025, 1:39pm UTC](https://forum.inductiveautomation.com/t/what-is-the-alternate-for-sleep/111001/8 "2025-09-26T13:39:15Z")

</div>

I try to find another way, but sometimes it's much easier to just use a `Timer`:

```python
from threading import Timer

def doSomethingLater():
		# do it...

Timer(0.2, doSomethingLater).start()

```

---

<div class="post-metadata">

**Author:** ![Samkcr](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@Samkcr](https://forum.inductiveautomation.com/u/Samkcr)\
**Post date:** [September 29, 2025, 1:50pm UTC](https://forum.inductiveautomation.com/t/what-is-the-alternate-for-sleep/111001/9 "2025-09-29T13:50:53Z")

</div>

Hi,

To clarify the use case, actually we are showing a load Icon while changing the view in the Display.

```python
def runAction(self):
Import time
if self.session.custom.Anim == True:
        while self.session.custom.Anim == True:
            for degree in range(0, 2000, 10):
                self.getChild("root").getChild("Icon").props.style.transform = 'rotate(' + str(degree) + 'deg)'
                time.sleep(0.25)
    
                if self.session.custom.Anim == False:
                    break  
            
            if self.session.custom.Anim == False:
                break  

```

On each view change we are enabling and disabling the custom property. This has been implemented previously. So just want to understand this will cause any performance issue? Shall we use **system.util.invokeAsynchronous** instead **time.sleep?** In thread Dashboard we are seeing multiple process is in state of Timed Waiting and Waiting. So we need to understand what is causing the below status…

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/1/b1d1c7aaf72560b8e4bd7b5482589fc0ea8edf03.png)

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [September 29, 2025, 2:59pm UTC](https://forum.inductiveautomation.com/t/what-is-the-alternate-for-sleep/111001/10 "2025-09-29T14:59:14Z")

</div>

I see you've made another post related to trying to determine what all the threads are doing. Are you experiencing a log of performance problems or something? Are these related?

> [@Need to understand reason behind the MQTT threads](https://forum.inductiveautomation.com/t/need-to-understand-reason-behind-the-mqtt-threads/111054):
>
> Hi, We are communicating with MES through MQTT. This works fine. But when we analyze the thread there are multiple threads in Waiting ,Runnable and Timed\_Waiting state. So we would like to understand why we are getting this threads? Does it affects performance of the ignition system?

---

<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:** [September 29, 2025, 3:37pm UTC](https://forum.inductiveautomation.com/t/what-is-the-alternate-for-sleep/111001/11 "2025-09-29T15:37:24Z")

</div>

That is an unbounded loop. You should **never** use those in Ignition event scripts, whether using `.sleep()` or not. Event scripts should run to completion in a repeatable duration, preferably in a handful of milliseconds.

Any longer delays should be handled by reacting to property changes as data flows in your UI, or by including polling bindings with associated scripts, perhaps in gateway timer events.

If you have a process that is heavily sequential, and you can prevent repeat launches while a prior is running, then `invokeAsynchronous` might be appropriate.
