Halt a Python script without Crashing Indigo

Posted on
Mon Jan 15, 2018 5:02 am
mclass offline
Posts: 312
Joined: May 13, 2015
Location: Melbourne, Australia

Halt a Python script without Crashing Indigo

Hi,
As a novice to Python, I am attempting to complete a Python script to access a cranky Daikin SkyFi API that fails to respond and generates error messages.

I am incorporating a “try/exception” code within the request section, but am struggling with what to do when an exception is raised in comms with the API.

Can I use a “quit()”, “exit()”, or “sys.exit” command within my script without crashing other Python code (including Indigo itself) or is there a more graceful means of ending that script? I’m running this as a file, not as an embedded script.

My script is executed on a regular basis by a schedule, and the results of the script is not time urgent (just the current status of the AC unit) so a retry on each failure is not warranted.

Any advice (or alternative approaches!) gratefully received!

mclass


Sent from my iPad using Tapatalk

Posted on
Mon Jan 15, 2018 6:53 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: Halt a Python script without Crashing Indigo

Indigo makes sure that all scripts and plugins are running independent of each other.
Exit() should be fine for you script.
And no indigo does not stop if you exit a script.


Sent from my iPhone using Tapatalk

Posted on
Mon Jan 15, 2018 9:21 am
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: Halt a Python script without Crashing Indigo

Why would you need to quit or exit your script if you are doing a try...exception to check on a persnickety API call? It will exit on its own after you execute it if it's just a script tied to an action group, if it's a plugin then it will go idle.

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Mon Jan 15, 2018 12:27 pm
mclass offline
Posts: 312
Joined: May 13, 2015
Location: Melbourne, Australia

Re: Halt a Python script without Crashing Indigo

kw123 wrote:
Indigo makes sure that all scripts and plugins are running independent of each other.
Exit() should be fine for you script.
And no indigo does not stop if you exit a script.


Thanks for that! I have tried exit() and sys.exit() and both generate a trace back to the event log that I would like to avoid, Is there a means of exiting “gracefully” without the traceback?


Sent from my iPad using Tapatalk

Posted on
Mon Jan 15, 2018 12:34 pm
mclass offline
Posts: 312
Joined: May 13, 2015
Location: Melbourne, Australia

Re: Halt a Python script without Crashing Indigo

Colorado4Wheeler wrote:
Why would you need to quit or exit your script if you are doing a try...exception to check on a persnickety API call? It will exit on its own after you execute it if it's just a script tied to an action group, if it's a plugin then it will go idle.


Thanks for your response. The script is tied to an acton group. If the try is “successful”, the script continues to parse the response from the request and then update indigo variables. So it would be good if I could exit gracefully upon the exception and/or skip the remainder of the script.

I guess the alternative is to include the parsing and the variable updates (quite a large “slab” of code) within the “try” and let it exit on its own, Maybe I’m trying to be too elegant?? :-)


Sent from my iPad using Tapatalk

Posted on
Mon Jan 15, 2018 12:37 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Halt a Python script without Crashing Indigo

mclass wrote:
Thanks for that! I have tried exit() and sys.exit() and both generate a trace back to the event log that I would like to avoid, Is there a means of exiting “gracefully” without the traceback?


Can you post the script? At least the part with the try/except?

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Jan 15, 2018 12:38 pm
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: Halt a Python script without Crashing Indigo

That works. You could also just break your loop to exit the script if that is how you are keeping it awake.

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Mon Jan 15, 2018 2:31 pm
mclass offline
Posts: 312
Joined: May 13, 2015
Location: Melbourne, Australia

Halt a Python script without Crashing Indigo

Thanks for your responses!

I seem to have solved the problem by placing the bulk of the script in the “try” section. I have also discovered that by “disguising” my script’s HTTP request as a browser request (using a user agent header) and changing the timing of the execution of the script to avoid what appears to be a regular UDP broadcast by the Daikin SKYFi module I appear to have alleviated my problem.
I believe that Daikin have discontinued this module, and am beginning to understand why! But has certainly been helpful in dragging me (screaming!) up the Python learning curve!

Thanks again for your assistance!

mclass


Sent from my iPad using Tapatalk

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest