# Delay in script

**URL:** <https://forum.inductiveautomation.com/t/delay-in-script/5145>\
**Category:** Ignition\
**Created:** [September 14, 2012, 3:33am UTC](https://forum.inductiveautomation.com/t/delay-in-script/5145 "2012-09-14T03:33:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tailfire](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@tailfire](https://forum.inductiveautomation.com/u/tailfire)\
**Post date:** [September 14, 2012, 3:33am UTC](https://forum.inductiveautomation.com/t/delay-in-script/5145/1 "2012-09-14T03:33:09Z")

</div>

I have a script event that sends an xml message and writes the response as a string back to a tag. I modified this so that it  
parses the response and writes only the data to a tag as an int. What I am hoping to do is add a scripted delay that I can adjust by ms or seconds right there in the script between the send of the message and the parse of the response. basically I am wanting to know how to do a ‘pause for x amount of time’ in the scripts…

---

<div class="post-metadata">

**Author:** ![tailfire](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@tailfire](https://forum.inductiveautomation.com/u/tailfire)\
**Post date:** [September 14, 2012, 4:36am UTC](https://forum.inductiveautomation.com/t/delay-in-script/5145/2 "2012-09-14T04:36:49Z")

</div>

import time  
time.sleep(1)

is this useful? I am not on my dev computer but this looks elegantly simple…

---

<div class="post-metadata">

**Author:** ![DomArmstrong](https://avatars.discourse-cdn.com/v4/letter/d/e495f1/32.png) [@DomArmstrong](https://forum.inductiveautomation.com/u/DomArmstrong)\
**Post date:** [September 14, 2012, 8:15am UTC](https://forum.inductiveautomation.com/t/delay-in-script/5145/3 "2012-09-14T08:15:34Z")

</div>

Hi Tallfire,

I have tried using sleep() in Jython a couple of times and it unfortunately doesn’t often behave as you would like it to. I believe this is to do with threading. Heres an example:

`from time import sleep
print 'a'
sleep(1)
print 'b'`  
This will sleep for 1 second and then print a, b at the same time.

I would advise looking at invokeLater.

[code]def b():  
import system  
print ‘b’

def a(b):  
import system  
print ‘a’  
system.util.invokeLater(b, 1000)

a(b)[/code]

This would do what you expect.

Dom

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [September 14, 2012, 7:10pm UTC](https://forum.inductiveautomation.com/t/delay-in-script/5145/4 "2012-09-14T19:10:58Z")

</div>

I agree with Dom - invokeLater() should help you in this situation.
