Currently Running Scripts Description

Is there a way to add a description to a thread so the description appears on the Currently Running Scripts page?

I’ve noticed a new section on the Gateway under Status->Diagnostics->Running Scripts which I’m finding really useful for some of my long running scripts.

I start my long running scripts using system.util.invokeAsynchronous() and can then identify the thread ID using this code:

import threading
ThreadId = threading.currentThread().ident

I’m then able to identify my scrip on the gateway page.
It would be really useful to also be able to add a description to these threads in my code so they’re even easier to identify!

You can do this with java’s Thread class constructors. With your background task suitably wrapped. (In lieu of system.util.invokeAsynchronous.)

Hmm, we should add an overload to invokeAsynchronous to do this - that’s a good idea. As it is now, invokeAsync tries to copy your description from the outer scope. You can manually provide one (that will render on the status page) by calling com.inductiveautomation.ignition.common.script.ScriptContext#setDescription from inside your async thread:

from com.inductiveautomation.ignition.common.script import ScriptContext
ScriptContext.setDescription("some description")
3 Likes

This feature made it into 8.0.15 - there’s a description parameter on system.util.invokeAsynchronous in all scopes. There’s also args and kwargs parameters - pass a sequence/map, respectively, so you don’t need to mess with partial anymore.

3 Likes

How would you add a description to a transform script? If they take a while or hang up, there is no description in the viewer.

Theoretically, by manually using the threadlocal ScriptContext. As soon as execution of a transform starts, it should be ‘locked’ to a particular thread ID and therefore safe to lock in a ThreadLocal.

I tried the attached script originally, and it did not add the description to the viewer. Do I need to do more?

Oh, I see. The way transforms are managed, the code you execute has already had its description set before it’s actually called. We’d probably have to add a UI element to set the description before firing the script; I don’t think setting it manually will be possible within the scope of a transform.

I filed a ticket to see if we could add the ability to specify a context; no promises, but I think that’s as much as I can offer for now.

Has there been any improvement here for transform scripts?

In the last three weeks since I filed that ticket? No.
If we decide to implement anything, it’ll be several releases out.