# How to interrupt script when the condition is false

**URL:** <https://forum.inductiveautomation.com/t/how-to-interrupt-script-when-the-condition-is-false/57147>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [March 13, 2022, 6:57pm UTC](https://forum.inductiveautomation.com/t/how-to-interrupt-script-when-the-condition-is-false/57147 "2022-03-13T18:57:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![splata](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@splata](https://forum.inductiveautomation.com/u/splata)\
**Post date:** [March 13, 2022, 6:57pm UTC](https://forum.inductiveautomation.com/t/how-to-interrupt-script-when-the-condition-is-false/57147/1 "2022-03-13T18:57:23Z")

</div>

hello

I did make a simple countdown timer in the property of value on progress bar ,when a condition is true the timer start to count down to 0 and every is going good to here.

```auto
	import time
	
	if value :
		tiempo=10
	else:
		tiempo=0
		
	while value and tiempo>0:
		
		tiempo =tiempo -1
		time.sleep (1)
		self.props.value=tiempo #value property of progress bar
		if value==False or tiempo==0:
		 	tiempo=0
			break
		
	return tiempo

```

I added an if condition to break the while condition , if I disable the condition intentionally. for 1 second the “if condition inside” of “while condition” break the countdown and the variable tiempo to 0  
but the script still executing in the gateway where was the countdown and the progress bar still showing the number to the script finish , i can see this behavior in the diagnostics runing scripts.

the question is is there other way to make this?, can i interrupt the script like in the diagnostics script tab?

regards

---

<div class="post-metadata">

**Author:** ![djs](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@djs](https://forum.inductiveautomation.com/u/djs)\
**Post date:** [March 14, 2022, 12:27pm UTC](https://forum.inductiveautomation.com/t/how-to-interrupt-script-when-the-condition-is-false/57147/2 "2022-03-14T12:27:17Z")

</div>

If I'm understanding your case correctly, this is might be because `time.sleep()` freezes the user interface for the duration of the delay. So when you set your condition to false elsewhere on the view it doesn't actually update the script until `sleep()` is done.

Regardless, using `time.sleep()` is incredibly bad practice for many reasons:

> [@Time.sleep function in Ignition](https://forum.inductiveautomation.com/t/time-sleep-function-in-ignition/10337/3):
>
> [quote=“dlaki”]Anyone here have tried to to use time.sleep function of time module in Ignition?[/quote]Nick hints at this, but let me be more explicit: Never, ever, use time.sleep or any other delay function in Ignition unless it is on its own asynchronous thread. Delays on the event dispatch thread (darn near everything in a client) will freeze the user interface for the duration of the delay. Just say no to any form of sleep. When you need delays, always use system.util.invokeLater() with …

> [@Perspective, time.sleep vs later.py](https://forum.inductiveautomation.com/t/perspective-time-sleep-vs-later-py/39955/2):
>
> time.sleep should be avoided in basically every scenario - the only exception I would maybe give is a dedicated thread spawned by invokeAsynchronous. later.py technically hooks into an internal class, but the signature of that class is pretty unlikely to change, and, crucially, it does not require a thread to be kept sleeping.
