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.
That is essentially what I was trying to do with the later.py library. It uses invokeAsynchronous to call my function (which runs the query) and then the library supplies a function which assigns the GUI component once the async function is complete. Though it sounds like I need to just use a message handler like you said instead of the library.
I see. I was under the impression that later.py would work with Perspective. I'll stick to the message handling. Does using system.perspective.sendMessage start in a new thread, similar to invokeAsynchronous? If so then could just run the query in the message handler, correct?
No, but Perspective is highly multi-threaded, so it effectively runs asynchronously.
later.py does include an emulation of invokeLater for use in gateway/perspective scope, but is intended for situations where its single thread is important for correctness.
You should avoid using invokeAsynchronous for Perspective UI tasks.