Page 1 of 1

Device creation in thread...

PostPosted: Sat Mar 17, 2018 4:34 pm
by FlyingDiver
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?

Re: Device creation in thread...

PostPosted: Sat Mar 17, 2018 5:28 pm
by Colorado4Wheeler
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!

Re: Device creation in thread...

PostPosted: Sun Mar 18, 2018 1:53 pm
by matt (support)
Having the devices created in a thread that completes in the background (after the initial menu action has been called and returned) is fine.

Re: Device creation in thread...

PostPosted: Sun Mar 18, 2018 1:55 pm
by FlyingDiver
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.

Re: Device creation in thread...

PostPosted: Sun Mar 18, 2018 3:11 pm
by Colorado4Wheeler
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.

Re: Device creation in thread...

PostPosted: Sun Mar 18, 2018 3:15 pm
by FlyingDiver
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.

Re: Device creation in thread...

PostPosted: Mon Mar 19, 2018 1:18 am
by jh71283
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

Re: Device creation in thread...

PostPosted: Mon Mar 19, 2018 3:00 pm
by Colorado4Wheeler
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 :).

Re: Device creation in thread...

PostPosted: Mon Mar 19, 2018 3:54 pm
by FlyingDiver
No problems here either. Device creation is working fine. New features are in beta now.