Perspective Property Change Scripts - missedEvents

Can anybody explain this a little more in depth?

https://docs.inductiveautomation.com/display/DOC81/Perspective+Property+Change+Scripts
image

From the 8.1.4 release notes:

Does it work like how tag event scripts go into a global queue with a limited amount of threads? Is it possible to miss events globally, or is it local to the property?

Thanks

The missedEvents are local to the property, because that’s where the thread limitation is. The thread count is sort of the issue, but so is the execution of the change script. If you have a change script that has any sort of sleep, or something like an array where there are potentially hundreds/thousands of items which could all trigger a long-running change script execution, then there is the potential for missed events by the next time the script executes.

Consider the following, and pretend you have a tag which changes every quarter of a second:

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
    from time import sleep
    sleep(1)
    system.perspective.sendMessage("SomeMessage")

Since the sleep immediately makes the script wait, there will be multiple values come through before the next time the thread allows this script to run. Supposing we have a tag which starts at 0 and increments by 1, then the first time through will have a value of 1 (value changed, not original value), and then the next script should pick up a value of 5. That’s less than ideal without a way to report that there were values in-between as well.

So if you encounter a missedEvent arg which is True (or maybe 1 - I can’t remember how it reports), then it means this specific property had other values between the currentValue and the last time the script executed.

1 Like