Error when executing a timer script

Ignition 8.0.12

I have a project function. I call this function from a timer script. but i get an error on the gateway.

the function works fine when I call it from somewhere in the project.

please help

the error is the following:

com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 27, in checkValues at java.base/java.util.concurrent.CompletableFuture.timedGet(Unknown Source) at java.base/java.util.concurrent.CompletableFuture.get(Unknown Source) at com.inductiveautomation.ignition.gateway.script.LegacyGatewayTagUtilities.read(LegacyGatewayTagUtilities.java:459) at com.inductiveautomation.ignition.common.script.builtin.LegacyTagUtilities.read(LegacyTagUtilities.java:168) at jdk.internal.reflect.GeneratedMethodAccessor13.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) java.util.concurrent.TimeoutException: java.util.concurrent.TimeoutException

at org.python.core.Py.JavaError(Py.java:552)

at org.python.core.Py.JavaError(Py.java:543)

at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)

at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.__call__(ScriptManager.java:521)

at org.python.core.PyObject.__call__(PyObject.java:480)

at org.python.core.PyObject.__call__(PyObject.java:484)

at org.python.pycode._pyx2262.checkValues$2(:35)

at org.python.pycode._pyx2262.call_function()

at org.python.core.PyTableCode.call(PyTableCode.java:171)

at org.python.core.PyBaseCode.call(PyBaseCode.java:308)

at org.python.core.PyFunction.function___call__(PyFunction.java:471)

at org.python.core.PyFunction.__call__(PyFunction.java:466)

at org.python.core.PyFunction.__call__(PyFunction.java:456)

at org.python.core.PyFunction.__call__(PyFunction.java:451)

at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:815)

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(ProjectScriptLifecycle.java:687)

at com.inductiveautomation.ignition.gateway.script.GatewayTagUtilities.lambda$readAsyncImpl$1(GatewayTagUtilities.java:138)

at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(Unknown Source)

at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(Unknown Source)

at java.base/java.util.concurrent.CompletableFuture.postComplete(Unknown Source)

at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.base/java.lang.Thread.run(Unknown Source)

Caused by: org.python.core.PyException: Traceback (most recent call last): File "", line 27, in checkValues at java.base/java.util.concurrent.CompletableFuture.timedGet(Unknown Source) at java.base/java.util.concurrent.CompletableFuture.get(Unknown Source) at com.inductiveautomation.ignition.gateway.script.LegacyGatewayTagUtilities.read(LegacyGatewayTagUtilities.java:459) at com.inductiveautomation.ignition.common.script.builtin.LegacyTagUtilities.read(LegacyTagUtilities.java:168) at jdk.internal.reflect.GeneratedMethodAccessor13.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) java.util.concurrent.TimeoutException: java.util.concurrent.TimeoutException

... 24 common frames omitted

Caused by: java.util.concurrent.TimeoutException: null

at java.base/java.util.concurrent.CompletableFuture.timedGet(Unknown Source)

at java.base/java.util.concurrent.CompletableFuture.get(Unknown Source)

at com.inductiveautomation.ignition.gateway.script.LegacyGatewayTagUtilities.read(LegacyGatewayTagUtilities.java:459)

at com.inductiveautomation.ignition.common.script.builtin.LegacyTagUtilities.read(LegacyTagUtilities.java:168)

at jdk.internal.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.base/java.lang.reflect.Method.invoke(Unknown Source)

at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)

... 21 common frames omitted

the function:

def activePowerCalc():
	
	
	def checkValues(asyncReturn):
		total=0
		i=0
		lista=[]
		label=[]
		value=[]
		
		for qv in asyncReturn:
			lista.append([qv.value,paths[i]])
			total+=qv.value
			i=i+1
		
		listaSorted=sorted(lista, reverse=True)
		
		listaSorted=listaSorted[0:5]
		
		for i in listaSorted:
			stationCode=i[1][5:8]
			stationNamePath='[BB2]'+stationCode+'/_'+stationCode+'/Description'
			stationName=system.tag.read(stationNamePath).value
			label.append(stationName)
			value.append(i[0])
		
		hdr = ['Label','Value']
		fullDS = zip(label,value)
	
		data=system.dataset.toDataSet(hdr,fullDS)	
		system.tag.write('[BB2]_Dashboard/_power',data)
	
				
		
	paths=[
		"[BB2]D01/ST01/PM_0001/PR2/MPPT",
		"[BB2]D02/ST01/PM_0001/PR2/MPPT",
		"[BB2]D03/ST01/PM_0001/PR2/MPPT",
		"[BB2]D04/ST01/PM_0001/PR2/MPPT",
		"[BB2]D05/ST01/PM_0001/PR2/MPPT",
		"[BB2]D09/ST01/PM_0001/PR2/MPPT",
		"[BB2]D10/ST01/PM_0001/PR2/MPPT",
		"[BB2]D13/ST01/PM_0001/PR2/MPPT",
		"[BB2]D14/ST01/PM_0001/PR2/MPPT",
		]
		
		
	
	system.tag.readAsync(paths, checkValues)```

I’m not sure if this is the underlying cause or not, but doing an async call in a timer script like this is very dangerous.

What can and likely will happen is that your timer script will execute at a faster rate than some or all of the readAsync calls take to complete and you end up with multiple outstanding async calls stacked up on top of each other.

You should rewrite this to be blocking and see if the issue still occurs.

1 Like

thanks for the reply Kevin.

I have to try using readBlocking instead readAsync ?

Yes, use readBlocking and there won’t be any need for the checkValues callback function, all of that logic just moves to the lines after the readBlocking call gives you the results.

thanks you Kevin, now it seems to work perfectly