How to detect and stop an endless loop in a gateway tag change event script

I am going to create a script that will use many consecutive loops waiting on a tag changes to progress. How can I tell if a script is stuck waiting for the tag change event to exit the loop? I do plan on haveing a timeout feature but as I develop the script I expect to have failures so want to be prepared for finding and stopping endless loops.

pseudo code would be:
Set transaction group handshake tag to zero
Trigger transaction group
Loop while transaction group handshake tag = zero .

Set transaction group handshake tag to zero
Trigger transaction group
Loop while transaction group handshake tag = zero .

Set transaction group handshake tag to zero
Trigger transaction group
Loop while transaction group handshake tag = zero .

and so on for 100 repeats.

This is an extremely dangerous script design in Ignition. Don't do any kind of busy-wait or sleep-wait in any Ignition event script. Full stop.

Instead, create a state machine, using either a memory tag, or, more robustly, a top-level project script collection object (typically a dictionary). Use gateway tag change events and gateway timer events to drive forward progress. Use a threading.RLock object instance to protect against simultaneous changes from different threads.

You may also want to look at the SFC module.

1 Like

Ewww! Or not. :cry:

Per your comments I am changing my plan to have zero wait loops..
Thanks

SFC has been reliable where I've used them. OTOH, I don't use them outside of a gateway scope either. I seem to notice that when people try to use them to interact with a client that things go pear shaped. Just my observation. That and a couple bucks will buy you a soda. :wink:

1 Like