# Threading and InvokeAsync

**URL:** <https://forum.inductiveautomation.com/t/threading-and-invokeasync/14828>\
**Category:** Ignition\
**Tags:** ignition78, scripting\
**Created:** [July 19, 2017, 2:46am UTC](https://forum.inductiveautomation.com/t/threading-and-invokeasync/14828 "2017-07-19T02:46:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamcoder](https://avatars.discourse-cdn.com/v4/letter/i/5f9b8f/32.png) [@iamcoder](https://forum.inductiveautomation.com/u/iamcoder)\
**Post date:** [July 19, 2017, 2:46am UTC](https://forum.inductiveautomation.com/t/threading-and-invokeasync/14828/1 "2017-07-19T02:46:15Z")

</div>

Hi There All,

I experiment some script on ignition but i’m not able to show the proper result.  
Just want to have delay on printing.

When not using async, it works. But I want to retain the usage of async.

Hope someone can help me.

Sample script:

```auto
import threading
import time

def count():
	for x in range(1,10):
		print x
		time.sleep(1)
	
def func():
	x = threading.Thread(target=count,args=())
	x.start()
	x.join()
system.util.invokeAsynchronous(func)

```

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [July 19, 2017, 4:01am UTC](https://forum.inductiveautomation.com/t/threading-and-invokeasync/14828/2 "2017-07-19T04:01:43Z")

</div>

> [@iamcoder](#):
>
> import time

```auto
import time

def longProcess():
	for i in range(10):
		print i
		time.sleep(1)
system.util.invokeAsynchronous(longProcess)

```

---

<div class="post-metadata">

**Author:** ![iamcoder](https://avatars.discourse-cdn.com/v4/letter/i/5f9b8f/32.png) [@iamcoder](https://forum.inductiveautomation.com/u/iamcoder)\
**Post date:** [July 19, 2017, 6:04am UTC](https://forum.inductiveautomation.com/t/threading-and-invokeasync/14828/3 "2017-07-19T06:04:53Z")

</div>

Hi thanks for your reply.

There is no way to combine the two?

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [July 19, 2017, 6:43am UTC](https://forum.inductiveautomation.com/t/threading-and-invokeasync/14828/4 "2017-07-19T06:43:43Z")

</div>

I just put your code on a button, and it gives the correct output (printing 1 to 9 in the designer console).

Are you sure it’s getting executed in the right context? When you run it in a gateway script or on a gateway tag trigger, the print will happen in the gateway and not in the designer. Did you try with a regular print?

The threading functionality is used in many external libraries, and these libraries work fine in Ignition. So using it in your scripts should also work fine.
