Threading and InvokeAsync

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:

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)
import time

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

Hi thanks for your reply.

There is no way to combine the two?

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.