Device creation in thread...

Posted on
Sat Mar 17, 2018 4:34 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Device creation in thread...

Before I go off and try to do something that's not going to work, I figured I'd ask.

I have a function that's going to take a long time to complete (10-15 sec) and will be creating a bunch of devices. I'm trying to run it from a Menu command. Right now, the Indigo UI times out before the operation completes, throwing an error in the log. The function does run, and could create the devices. But I'd like to avoid the UI error, so I was going to run the actual operation in another thread. Will that cause issues with the device creation?

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

Posted on
Sat Mar 17, 2018 5:28 pm
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: Device creation in thread...

You could use the new polling feature that was introduced in 7.1 that allows you to make status calls. I don't think threading device creation would cause a problem but that's an easy 5 minute test but I love the idea because if that does work then that answers a couple issues I have with long menu actions too that I hadn't considered!

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
Sun Mar 18, 2018 1:53 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Device creation in thread...

Having the devices created in a thread that completes in the background (after the initial menu action has been called and returned) is fine.

Image

Posted on
Sun Mar 18, 2018 1:55 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Device creation in thread...

matt (support) wrote:
Having the devices created in a thread that completes in the background (after the initial menu action has been called and returned) is fine.


That's what I'm working on now. Got a stumper going though. My parsing routine is working fine, but as soon as I try to call another function to actually create the device, I get an exception. Grrr.

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

Posted on
Sun Mar 18, 2018 3:11 pm
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: Device creation in thread...

I've been using threading a lot lately to get around script timeouts for some of my longer actions that require sleep times or other delays, been working amazing.

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
Sun Mar 18, 2018 3:15 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Device creation in thread...

Colorado4Wheeler wrote:
I've been using threading a lot lately to get around script timeouts for some of my longer actions that require sleep times or other delays, been working amazing.


I think it was a stupid coding error that I wasn't seeing because there's a try block somewhere that was capturing it. I didn't write the original code in this plugin, and there's some gotchas there.

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

Posted on
Mon Mar 19, 2018 1:18 am
jh71283 offline
Posts: 127
Joined: Jun 16, 2014

Re: Device creation in thread...

Do exceptions work ok for you guys on a secondary thread?

My MQTT plugin uses a threads to handle incoming messages, but if there is an exception it does not show up in the log.

I have years of Dev experience (decades in fact) but I am a python noob!


Sent from my iPhone using Tapatalk

Posted on
Mon Mar 19, 2018 3:00 pm
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: Device creation in thread...

jh71283 wrote:
Do exceptions work ok for you guys on a secondary thread?

They work fine for me, how are you logging? Heck, 2/3rds of my HomeKit Bridge plugin is threaded, if I couldn't trap exceptions I would be in big trouble :).

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 Mar 19, 2018 3:54 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Device creation in thread...

No problems here either. Device creation is working fine. New features are in beta now.

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

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 7 guests