Perspective views and long running scripts

As far as I understand, Python scripts run on the gateway. Suppose a button in a Perspective view starts a long running script, after which I have to update a property of the view: since the Python script runs on the gateway, my UI experience is fluid, even while that script is running. What's then the purpose of a system.util.invokeAsynchronousand system.util.invokeLater calls in that case? What should I care of, when a button starts a long running script in a Perspective view?

Thanks in advance, regards

This has no purpose outside of vision.

This will return the event handler immediately and move the work to another thread. This prevents the sessions's scripting request being held open. So if you have a script doing a bunch of things, and you want to spin off one part of the thing while letting the rest of the things finish, you'd use this.

This adds complexity, though, because if you have a button smasher (like myself, I super smash bros UI buttons), you have to add protections to keep the calls from stacking up. Something like:

if self.custom.busy:
    return

self.custom.busy = True
component = self
logger = system.util.getLogger("myProject")

def work():
    try:
        component.custom.result = do_the_slow_operation()
    except:
        logger.exception("Long operation failed")
    finally:
        component.custom.busy = False

system.util.invokeAsynchronous(
    work,
    description="Long Perspective operation"
)