Timing issue with multiple scripts in Action Group...

Posted on
Wed Mar 27, 2019 3:08 pm
russg offline
Posts: 46
Joined: Oct 02, 2014

Timing issue with multiple scripts in Action Group...

Hi Folks,
Sorry if this is a silly question, I'm having trouble sequencing multiple scripts in an Action Group. In my action group I have this:

- python script that sets a variable vTxtMsgBody to "hello"
- execute action group "send text message". (this is another action group that contains a python script that sends a text message using vTxtMsgBody)

However, the text message script sends the message BEFORE the variable vTxtMsgBody gets updated. I tried this:
- python script that sets a variable vTxtMsgBody to "hello"
- python script that uses time.sleep(5), adding a 5 second delay
- execute action group "send text message". (this is another action group that contains a python script that sends a text message using vTxtMsgBody)

In this case, the text message still gets sent, before the sleep script even returns.

It looks like Indigo is shelling the scripts one after another, without waiting for the prior script to return. Is this correct? If so, any ideas on how to properly organize this? Fundamentally, I need to be able to set multiple Indigo variables in a Python script and then have another script that uses the same set of Indigo variables execute, but only after the set of Indigo variables have been updated.

Any suggestions on what I'm doing wrong?

Thanks in advance!
-russg

Posted on
Wed Mar 27, 2019 3:40 pm
jay (support) offline
Site Admin
User avatar
Posts: 18212
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Timing issue with multiple scripts in Action Group...

Indigo attempts to run actions in parallel as much as possible in order for their performance to be better. Usually, I'd recommend adding in delays for each action.

However, you should just execute the group in your script rather than a separate action:

Code: Select all
indigo.actionGroup.execute(IDOFACTIONGROUP)


So you only have 1 action that runs the script, and the script 1) changes the value then 2) runs the action group. No delays needed (and, indeed, you shouldn't add time.sleep() in any embedded Python scripts because they have max 10 seconds to complete before being killed and they will hold up any other embedded scripts until they are done).

Seems like there's even more optimization that could be done (having the second script actually be a shared module to which you can pass the appropriate parameters) then you just call the shared method from the first script passing in the correct data. Might eliminate Indigo variables entirely. See this section of the docs for details. Note that Indigo 7.3 (shipping soon) will have an even more convenient place to put shared modules like this (that will move with your Indigo Install if you move to a different Mac), but the documented location works just as well.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Mar 27, 2019 5:13 pm
russg offline
Posts: 46
Joined: Oct 02, 2014

Re: Timing issue with multiple scripts in Action Group...

Thanks for the rapid response Jay! That explains things, and makes sense from a performance perspective. Delays always make me nervous, so I need to rethink it so it's entirely event driven.

I have several (12-ish) variables that get shared. I've never looked at using python methods in Indigo, but I'll take a look. To be honest, I'm new enough at Indigo that trying to wrap my OOP mind set around using that embedded into Indigo makes my brain hurt. I keep trying to go back to a pure object oriented design, but I'm not good enough to extend that to Indigo & Python yet. I envy the users who can and do!

thanks again,
-russg

Posted on
Thu Mar 28, 2019 9:32 am
jay (support) offline
Site Admin
User avatar
Posts: 18212
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Timing issue with multiple scripts in Action Group...

russg wrote:
To be honest, I'm new enough at Indigo that trying to wrap my OOP mind set around using that embedded into Indigo makes my brain hurt. I keep trying to go back to a pure object oriented design, but I'm not good enough to extend that to Indigo & Python yet. I envy the users who can and do!


Python is most definitely an OOP language - in fact everything in Python is an object. The key is to determine if building up objects is in fact what's really necessary. This is a very common issue with using object-oriented languages - many times the developer gets TOO wrapped up in building an object hierarchy that they sacrifice simplicity. The Indigo Object Model (IOM for short, and is the generic name of our API), is a blend of traditional objects and more light-weight functional designs. If you haven't already, it's worth reading through the Scripting Tutorial which focuses on using the IOM in scripts and helps to distinguish between objects and the methods that operate on them.

And, of course, for anyone that's really getting into Python for the first time, we recommending working through one of the many Python tutorials out on the net (find one that's 2.7 since that's the version we're on).

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 5 guests

cron