Good afternoon.
In Ignition 8.0.14, when I try to use the “system.util.invokeLater ()” function in a Gateway Event Script (tag change), this error is logged in the logs:
This is the code:
def runThisLater():
import system
Logger_Script = system.util.getLogger("probar")
Logger_Script.info("hola")
system.util.invokeLater(runThisLater, 3000)
Best Regards.
invokeLater
is only available when code is executing in client/designer scope. If you understand what it’s actually doing - running some piece of code later on the Swing Event Dispatch Thread, then it should be obvious why.
Perhaps you are misusing/abusing invokeLater
?
I think your answer is very hasty. According to the documentation: “The Threading Library has a Timer function that works in a very similar fashion to invokeLater.”
https://docs.inductiveautomation.com/display/DOC81/Adding+a+Delay+to+a+Script
“Timer” does work in Gateway Events Script, so I thought “invokeLater” would work too.
When a tag changes, I need to execute a function after a few seconds, that’s why “invokeLater” seemed correct to me.
I understand that I have to use “Timer”.
Best Regards.
1 Like
@pturmel has a later.py
implementation here on the forums that uses an (internal) class to allow for the ‘delayed execution’ functionality of invokeLater
to work on the gateway.
Bleh, I wish the training team hadn’t written those docs advocating the use of invokeLater
as a convenient way to introduce a delay. That’s really not what it’s for.
Jython’s Timer seems fine, but it’s conceptually no different than just using invokeAsync
and then sleeping as the first thing you do for the amount of delay you desire. Both end up using a dedicated Thread.
2 Likes