# Alternative to sleep

**URL:** <https://forum.inductiveautomation.com/t/alternative-to-sleep/86843>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [March 5, 2024, 6:06pm UTC](https://forum.inductiveautomation.com/t/alternative-to-sleep/86843 "2024-03-05T18:06:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [March 5, 2024, 6:06pm UTC](https://forum.inductiveautomation.com/t/alternative-to-sleep/86843/1 "2024-03-05T18:06:09Z")

</div>

Hello everyone, I think this topic is already discussed before, but I can't find the right answer, I hope someone can help me.

I have a script that I turn on to be visible in the **label component** for 5 sec to let the user know the error.  
I'm using something like this below:

```auto
def ErrorMsg(vtext):
from time import sleep

self.getChild("Label").meta.visible = True
self.getChild("Label").props.text = "Error during scanning the barcode"
sleep(5)
self.getChild("Label").meta.visible = False
self.getChild("Label").props.text = ""

```

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 5, 2024, 6:09pm UTC](https://forum.inductiveautomation.com/t/alternative-to-sleep/86843/2 "2024-03-05T18:09:35Z")

</div>

I would look into using [system.util.invokeAsynchronous](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-util/system-util-invokeAsynchronous).

Alternatively, why remove the warning before a successful attempt. I'm aware there may be requirements, but as a user of software I dislike when error messages are transient because I often trigger some action and look away. If the error/warning disappears after some time, I would then look back to my focus area and it would appear no action was taken at all.

Also, why are you suing a Text Field (Input) as a display? Why not use a Label?

Also also, if you're toggling visibility, why even bother clearing the text of the Text Field?

---

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [March 5, 2024, 6:24pm UTC](https://forum.inductiveautomation.com/t/alternative-to-sleep/86843/3 "2024-03-05T18:24:52Z")

</div>

Sorry, changed the post.  
It is a Label component.

I will think about your suggestion to keep the error msg thanks.  
I'm clearing it because I'm using the same label to display other messages. I could keep it and just change the text to the new one.

In case I would like to have this 5s delay, I was wondering if you could show me how to implement that in this sample code.

Another question is about `.focus()` I'm using sleep too to make work.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 5, 2024, 6:30pm UTC](https://forum.inductiveautomation.com/t/alternative-to-sleep/86843/4 "2024-03-05T18:30:47Z")

</div>

I would make a custom prop somewhere to hold the timestamp of the error event.  
You can then use an expression binding like:

```auto
secondsBetween({path.to.the.timestamp}, now()) < 5

```

on the visibility prop.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 5, 2024, 6:35pm UTC](https://forum.inductiveautomation.com/t/alternative-to-sleep/86843/5 "2024-03-05T18:35:49Z")

</div>

I like the solution provided by @JordanCClark better than invokeAsynchronous, but here you go:

```python
def runAction(self, event):
	def reset():
		from time import sleep
		sleep(5)
		self.props.text = "Reset"
	self.props.text = "Clicked"
	system.util.invokeAsynchronous(reset)

```
