Perspective - Message handler & later.py GUI component assignments

We have an application that triggers the execution of a query which can run for several seconds, and during that time we are showing a loading indicator by greying out certain UI components and displaying a spinning loading icon.

This was working well with the later.py library. We would call the named query via scripting in an asynchronous function (using later.callAsync), and then set the "is loading" component back to false, along with several other GUI components, using later.assignLater().

Well, I found out that Message Handler scripts will execute in a separate asynchronous thread. If I moved my query call from the callAsync function to a Message Handler, should I still be using later.assignLater() for the assignment of GUI components? Or can I assign a value directly since the message is executing in a separate thread? I'm having trouble understanding the difference between something executed from the callAsync, and something executed from a Message Handler.

Thanks in advance

Wouldn't you be calling the query with: https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-util/system-util-invokeAsynchronous
Then from that async function sending a message to any listening message handlers in the session that sets the isLoading parameter to false? That way the query runs happily in the background and any script that depends on it just listens for the message it will send on completion, no extra configuration needed?

Perspective is a totally different threading environment from Vision. Use message handlers as needed instead of using later.assignLater().

1 Like