Plugin Shutdown error

Forum rules

This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo

Posted on
Fri Aug 09, 2013 7:03 am
jd10884 offline
Posts: 39
Joined: Feb 18, 2012

Plugin Shutdown error

I have written a plugin that works fine except it will not reload or disable without this error:

Error process (pid 225) failed to quit after polite request -- forcing it to quit now

I have stripped the plugin.py code down to this and still I get the above error. Obviously there is something fundamentally wrong in my basic code. With this plugin.py
in my plugin, it writes to the debug log every 60 seconds just fine but I get the above error when I try to disable or reload the plugin.

Can you please see what is causing this error?

plugin.py as follows:
Code: Select all
#! /usr/bin/env python
# -*- coding: utf-8 -*-

class Plugin(indigo.PluginBase):

      
   def __init__(self, pluginId, pluginDisplayName, pluginVersion, pluginPrefs):
      indigo.PluginBase.__init__(self, pluginId, pluginDisplayName, pluginVersion, pluginPrefs)
      
      self.debug = pluginPrefs.get("showDebugInfo", True)
      
   ########################################
   
   def __del__(self):
      indigo.PluginBase.__del__(self)
   
   ########################################
   
   def runConcurrentThread(self):
      
      pInterval = 60
      
      self.debugLog("Starting concurrent thread")
      
      self.debugLog("L98 set to update every %s %s" %(pInterval, 'seconds'))
      
      try:
         while True:
            
            self.sleep(int(pInterval))
            self.update()
      
      except self.StopThread:
         pass
         
   ########################################
   
   def stopConcurrentThread(self):
      self.stopThread = True

   ########################################
      
   def update(self):
      
      self.debugLog('L272 testing')


Thanks in advance and I look forward to your comments.

Posted on
Fri Aug 09, 2013 8:01 am
matt (support) offline
Site Admin
User avatar
Posts: 20613
Joined: Jan 27, 2003
Location: Texas

Re: Plugin Shutdown error

Remove these two lines:

Code: Select all
   def stopConcurrentThread(self):
      self.stopThread = True


And I believe it will work correctly. The base plugin class (which your plugin inherits from) defines that method already. It does what your method does (set self.stopThread to True) and it also writes to a stopThreadPipe that is used internally by the base implementation to abort the sleep() call. Since your implementation is missing the latter (and doesn't call the base implementation), the sleep() method is not properly aborting when the plugin is told to shutdown.

Image

Posted on
Fri Aug 09, 2013 9:52 am
jd10884 offline
Posts: 39
Joined: Feb 18, 2012

Re: Plugin Shutdown error

Thanks Matt for the Rapid response :D

One more Question?


How would you stop the thread in an Exception like so?

Code: Select all
except Exception, e:
   self.debugLog("****** L357 error %s %s "  %(device.name, e))
   if e == '[Errno 6] Device not configured':
      self.StopThread


Thanks in advance
Jeff

Posted on
Fri Aug 09, 2013 11:28 am
matt (support) offline
Site Admin
User avatar
Posts: 20613
Joined: Jan 27, 2003
Location: Texas

Re: Plugin Shutdown error

If you call:

Code: Select all
self.stopConcurrentThread()

Then that will set the flags that cause sleep() to throw an exception. Note it doesn't immediately throw an exception in the thread that makes the call since you would normally call this from a different thread than the runConcurrentThread() you are trying to abort.

Image

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 0 guests