Plugin Shutdown error

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
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
jd10884
Posts: 39
Joined: Sat Feb 18, 2012 2:24 pm

Plugin Shutdown error

Post by jd10884 »

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.
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Plugin Shutdown error

Post by matt (support) »

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
jd10884
Posts: 39
Joined: Sat Feb 18, 2012 2:24 pm

Re: Plugin Shutdown error

Post by jd10884 »

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
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Plugin Shutdown error

Post by matt (support) »

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
Locked

Return to “Extending Indigo with Plugins and Python”