Proper way to restart the concurrent thread

Posted on
Thu Jul 13, 2017 2:39 pm
vtmikel offline
Posts: 644
Joined: Aug 31, 2012
Location: Boston, MA

Proper way to restart the concurrent thread

Hi-

I have a concurrent thread that synchronizes the state on the server. In the plugin configuration, I'm allowing to edit the polling interval. How do I restart the concurrent thread when the polling interval changes?

Thanks.
Mike

Posted on
Thu Jul 13, 2017 2:56 pm
FlyingDiver offline
User avatar
Posts: 7221
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Proper way to restart the concurrent thread

Why do you need to restart the thread? In my plugins, I check to see if a poll is required pretty frequently (minimum polling interval), but don't actually do the poll unless it's time. Something like:

Code: Select all
   def runConcurrentThread(self):

      try:
         while True:
            if (self.pollFrequency > 0.0) and (time.time() > self.next_poll):
               self.next_poll = time.time() + self.pollFrequency
               for dev in indigo.devices.iter("self"):
                  if (dev.deviceTypeId == "twilioNumber"):
                     self.checkMessages(dev)
            self.sleep(60.0)


In this case, the minimum polling interval is one minute. Then, to update the polling interval:

Code: Select all
   def closedPrefsConfigUi(self, valuesDict, userCancelled):
      if not userCancelled:
         self.pollFrequency = float(self.pluginPrefs.get('pollFrequency', "10")) * 60.0
         self.logger.debug(u"pollFrequency = " + str(self.pollFrequency))
         self.next_poll = time.time()

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

Posted on
Thu Jul 13, 2017 3:56 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Proper way to restart the concurrent thread

+1 on FlyingDiver's suggestion - no need to restart it.

To answer the question though, you can't restart runConcurrentThread.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jul 14, 2017 8:18 am
vtmikel offline
Posts: 644
Joined: Aug 31, 2012
Location: Boston, MA

Re: Proper way to restart the concurrent thread

Thanks both, this is helpful.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 10 guests