Find and share HowTos to various installations / configurations!
6 posts • Page 1 of 1
6 posts
• Page 1 of 1
RudiKreiner
Posts:198
Joined: Mon May 16, 2011 2:10 pm
Function at exit of control script
Postby RudiKreiner »
How can I run some code whenever a control script exits for any reason?
I'm thinking of somethingl like the signal() function in C, that can be used to clean things up before exiting a program.
There is no signal() function described in the CONTROL help though.
Can than be done some other way in a control script?
A control manager can run multiple scripts. You could run a second 'monitor' script. Now the question is : how to detect that script one has just exited (or crashed).
I think you have two options:
* You could use the _CtrlDebug datapoint to ask a manager for the scripts that are running. When your script disappears you could do the cleanupo
* Your script (to be monitored) could set a heartbeat
I don't believe that you will find anything like the signal()
Depends on what you mean with "a control script". If you mean ANY, e.g. also a script which is executed as result of a click in a button, etc. then there is no solution.
If you are only thinking about a ctrl script running in a ctrl manager and it's the only script in that, then you can run a second ctrl manager using the internal _Connections DP to monitor if the other CTRL manager has stopped.
However this does not allow to clean things up in the first ctrl script. This way described here is only "post mortem"
Thanks for the information.
Handling this with another control was my plan B, but I was hoping I wouldn't need that because it generates more overhead.
As you suggested I could write another control script with another manager number
In that script I could connect to _Connections.Ctrl.ManNums and run my code whenever the manager number of my other control script disappears from the list.
But this control does not know anything about what the other control is doing, except what it can see by looking at datapoints, so that restricts the functionality a bit too.
And what do I do if this control is not running either . . .
I guess what I am trying to say is that a function similar to the terminate script for panels would be a nice feature for control scripts too