Threads in Plugins

Posted on
Sun Apr 02, 2017 9:57 am
bkmar1192 offline
Posts: 274
Joined: Sep 12, 2015

Threads in Plugins

A post from earlier this week regarding multiprocessing got me pondering my Security Camera plugin. My plugin spawns a separate thread each time it goes out to capture image from a camera (indigo device). Once it is done with he capture it clears the thread and repeats the process. I do this so the camera run in parallel and can each capture an image every x seconds. So my questions are:

1) Is there a more efficient way to do this?
2) Is there a way for Indigo to spawn a separate process for each device in a plugin?
3) I don't think multi-processing makes a difference here since my threads only stay open for, at most, a couple of seconds. Is that true?
4) Would it be better to spawn a separate process for each camera and keep it open versus closing it and opening it again?

I run Security Camera 24x7 for weeks at a time without much problem. Just trying to determine if I can improve performance.

thanks for any guidance.

Posted on
Sun Apr 02, 2017 11:41 am
autolog offline
Posts: 3989
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Threads in Plugins

I would think have a thread for each camera and use queueing. So each thread has a queue which it monitors for messages and responds according . In that way you are not having to start and stop threads. The only downside (minimal IMHO) is that the thread will be consuming some storage for each camera. It won't be using any CPU cycles while it waits for the next message.
My FoscamHD plugin uses this mechanism (if that helps). :)

Posted on
Sun Apr 02, 2017 12:08 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Threads in Plugins

The iTunes plugin also uses the pattern @autolog describes. I definitely wouldn't be starting/stopping threads if it only takes a few seconds to complete the operation. Either bypass threads altogether (to simplify) or just start one per camera and use queues to exchange data as necessary.

The multiprocessing API discussed in another topic is good if you have compute intensive things that need to happen in parallel to the normal operation of the plugin because it does create a completely separate process. Doesn't sound like this would be useful for your plugin though.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 8 guests