Hey Ignition Gurus,
I am looking for a way to keep a while loop alive inside of ignition that doesn't bog down any resources.
In our last project, we created a while loop in a thread to behave as a TCP Server for connecting to scanners to consume data very quickly. Trouble is, whenever ignition saves, all scripts move in memory and all of a sudden you get funky issues like type(x) != type(x) after save.
We solved this problem by creating a reference point for the TCP server in the utils.globals() and it would destroy itself if it couldn't find its own reference anymore affectively restarting itself. However, for some reason, we had weird issues when using this with ignition redundancy where we would get multiple instances of the same instance type not destroying itself.
I want to know if there is a correct place to run an infinite while loop that essentially dies on save. I am looking for similar functionality to the arduino style ide where there is an init() func that runs once and a loop() func that runs repeatedly until the end of time. The goal would be that the script would die during save and automagically restart itself.
A few aux thoughts and considerations we thought about:
- Holding in Tag Event Script, but then it locks up portion of thread pool. Not scalable.
- Holding in Gateway event. Could lock up in timer script, but I don't constantly check if my loop is running when I don't have to.
- Running in script directly, but then it will run forever and lock up script loading.
Is there a right place to do this in ignition? I wish that the gateway had a keep alive event handler that would just run a script indefinitely.