# Multi-threaded scripting

**URL:** <https://forum.inductiveautomation.com/t/multi-threaded-scripting/2410>\
**Category:** General Discussion\
**Created:** [December 9, 2010, 8:49pm UTC](https://forum.inductiveautomation.com/t/multi-threaded-scripting/2410 "2010-12-09T20:49:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdana](https://avatars.discourse-cdn.com/v4/letter/j/c89c15/32.png) [@jdana](https://forum.inductiveautomation.com/u/jdana)\
**Post date:** [December 9, 2010, 8:49pm UTC](https://forum.inductiveautomation.com/t/multi-threaded-scripting/2410/1 "2010-12-09T20:49:48Z")

</div>

Is scripting in Ignition multi-threaded and if so, are there limitations to that. Is there ever a time where you would call a sleep function in a script and that would cause any of the basic system functions to hang up?

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [December 9, 2010, 10:11pm UTC](https://forum.inductiveautomation.com/t/multi-threaded-scripting/2410/2 "2010-12-09T22:11:38Z")

</div>

Scripting in Ignition is multi-threaded in certain locations. For example, Global Event Scripts Client and Gateway (timer scripts, tag change scripts, etc) are multi-threaded. However, event handlers on components run in the GUI thread by default. That means if you have a long running script on a actionPerformed, for example, it will hang the GUI until the script is finished. A lot of people don’t like that behavior because they can’t change screens or interact with the client untli the script is complete.

For that reason we have developed a couple of helper functions to run scripts in different threads. The main scripting function is system.util.invokeAsynchronous located at the following page in the user manual:

[http://www.inductiveautomation.com/support/usermanuals/ignition/system\_util\_invokeasynchronous.htm](http://www.inductiveautomation.com/support/usermanuals/ignition/system_util_invokeasynchronous.htm)

That function allows you to take any long running script and run it in a separate thread than the GUI thread. If you want your script to interact with the GUI you MUST call system.util.invokeLater. Take a look at the warning on the system.util.invokeAsynchronous function.

Now, if you are running a process in a separate thread you can simply call a sleep function to make it wait for some period of time. Here is an example:`import time
time.sleep(60)`I hope this helps you out.
