Page 1 of 1

Terminating a linked python script process

PostPosted: Fri Feb 03, 2017 10:47 am
by skoeppen
One of my python scripts includes the following code to turn an I/O Linc output on after a specified delay:

Code: Select all
import time
TimeDelay=indigo.variables[295357455]    # typically 5-10 minutes
delay_secs = 60*int(TimeDelay.value)
time.sleep(delay_secs)
OHdisable=indigo.devices[444538556]
indigo.iodevice.setBinaryOutput(OHdisable, index=0, value=True) 


There are times when I would like to terminate this script before the end of the time delay. I'd like to do it by running another python script set up as an Action Group. I've been going through the python documentation regarding processes and threads but I can't figure out how to do this.

A related question. Is there a way to show the current processes associated with a linked script? I know how to kill a process using the MacOS Activity Monitor but I looked in the Activity Monitor and I don't even see the Indigo Server process. Where would I find a list of processes associated with Indigo and python scripts?

Re: Terminating a linked python script process

PostPosted: Fri Feb 03, 2017 11:29 am
by jay (support)
skoeppen wrote:
There are times when I would like to terminate this script before the end of the time delay. I'd like to do it by running another python script set up as an Action Group. I've been going through the python documentation regarding processes and threads but I can't figure out how to do this.


There's nothing built-in to do it. An alternate approach would be to go into a tight loop (rather than a long sleep) that checks the value of another Indigo variable to see if the script should continue (refresh the variable, check the value, if it's still true then sleep for several seconds and check again, repeat until you've collectively waited then exit the loop). Then you'd just need to set that variable to false (or something) when you want the script to stop. At the start of the script, set it to true so it will definitely continue on that run of the script.

If you don't really care about the wait itself, but only want to stop the stuff from happening after the wait, then do the wait, check the variable to see if it should perform the actions, and make the decision then. That would avoid the polling.

skoeppen wrote:
A related question. Is there a way to show the current processes associated with a linked script? I know how to kill a process using the MacOS Activity Monitor but I looked in the Activity Monitor and I don't even see the Indigo Server process. Where would I find a list of processes associated with Indigo and python scripts?


Nothing built-in. All external scripts run in an IndigoPluginHost process (just like plugins do). You could try to find the PID based on parsing out the output of ps or something but that seems like a lot of work.

Re: Terminating a linked python script process

PostPosted: Fri Feb 03, 2017 11:40 am
by skoeppen
Thanks Jay. I don't care about the wait so your idea about checking a variable after the wait and prior to executing the subsequent code is a good approach.

FYI, I DO see the IndigoServer process and several IndigoPluginHost processes in the MacOS Activity Monitor. I was looking in the Activity Monitor on my MacBook Pro instead of the Mac mini where Indigo is running.