system.util.invokeAsynchronous Error calling from Custom Method

Can someone point out what am I doing wrong? -- Thanks

Error:

Error

com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 3, in func at com.inductiveautomation.perspective.gateway.script.AbstractScriptingFunctions.getSession(AbstractScriptingFunctions.java:104) at com.inductiveautomation.perspective.gateway.script.AbstractScriptingFunctions.operateOnSession(AbstractScriptingFunctions.java:118) at com.inductiveautomation.perspective.gateway.script.AbstractScriptingFunctions.operateOnPage(AbstractScriptingFunctions.java:47) at com.inductiveautomation.perspective.gateway.script.PerspectiveScriptingFunctions.print(PerspectiveScriptingFunctions.java:704) at jdk.internal.reflect.GeneratedMethodAccessor452.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: No perspective session attached to this thread.
at org.python.core.Py.JavaError(Py.java:545)
at org.python.core.Py.JavaError(Py.java:536)
at org.python.core.PyReflectedFunction.call(PyReflectedFunction.java:192)
at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.call(ScriptManager.java:553)
at org.python.core.PyObject.call(PyObject.java:461)
at org.python.core.PyObject.call(PyObject.java:465)
at org.python.pycode.pyx24743.func$2(:3)
at org.python.pycode.pyx24743.call_function()
at org.python.core.PyTableCode.call(PyTableCode.java:173)
at org.python.core.PyBaseCode.call(PyBaseCode.java:306)
at org.python.core.PyFunction.function___call
(PyFunction.java:474)
at org.python.core.PyFunction.call(PyFunction.java:469)
at org.python.core.PyFunction.call(PyFunction.java:464)
at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:847)
at com.inductiveautomation.ignition.gateway.script.GatewaySystemUtilities.lambda$_invokeAsyncImpl$0(GatewaySystemUtilities.java:152)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: org.python.core.PyException: java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: No perspective session attached to this thread.
... 16 common frames omitted
Caused by: java.lang.IllegalArgumentException: No perspective session attached to this thread.
at com.inductiveautomation.perspective.gateway.script.AbstractScriptingFunctions.getSession(AbstractScriptingFunctions.java:104)
at com.inductiveautomation.perspective.gateway.script.AbstractScriptingFunctions.operateOnSession(AbstractScriptingFunctions.java:118)
at com.inductiveautomation.perspective.gateway.script.AbstractScriptingFunctions.operateOnPage(AbstractScriptingFunctions.java:47)
at com.inductiveautomation.perspective.gateway.script.PerspectiveScriptingFunctions.print(PerspectiveScriptingFunctions.java:704)
at jdk.internal.reflect.GeneratedMethodAccessor452.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:190)
... 13 common frames omitted

Asynchronous threads are started without carrying the original thread's self-identifying locals. You must ensure you create the thread with default arguments to carry that information, or, with somewhat recent versions of Ignition, pass a Perspective component as a function argument.

I am stuck..
What I am trying to do:
When table has new row. I want the new row to be highlighted for 5 secs.
So on the query code, I add wait 5 sec, and re execute the query.
Not to create a bottle neck on the query code, I then planned to invokeAsynchronous the re-query.

edit: I think I should be able to implement this using property change script.
Thanks.

Tangent: this is fixed in 8.3.0.

Not sure that won't backfire. Deliberate long-lived threads started by a UI will prevent memory reclaim for the session.

Fair point, but I err on the principle of least surprise. It's much easier to start your own thread than to carry your own script context over.

And actually, now that I think about it more, Perspective's specific context won't be carried over, only the general purpose platform level default DB, tag provider, etc. So it won't solve the issue described by the OP or risk memory "leaking".

1 Like