Page 2 of 2

Re: how to call a method in the plugin class

PostPosted: Mon Oct 09, 2017 4:42 pm
by matt (support)
I'm confused. You are talking about a problem when the plugin is being shutdown ? If so, choose the Disable menu for that plugin, let Indigo try to shut it down then copy/paste the entire Event Log window contents starting with where you performed the disable.

Re: how to call a method in the plugin class

PostPosted: Mon Oct 09, 2017 5:40 pm
by kw123
when setting down / restart
Code: Select all
18:28:35
18:29:13                     -in Line '8062' has error='UnexpectedNullError -- CClientMgr not created'
18:29:13                     - pi2  RPI{u'ipNumberPiSendTo': u'192.168.1.22', u'sendToIndigoSecs': u'90.0', u'piNumberReceived': u'2', u'sensorList': u'Wire18B20*137345691,BLEconnect*65802248,i2cOPT3001*1497048646*68,i2cBMExx*1336842918*119*17,i2cTSL2561*864053974*57,', u'piOnOff': u'1', u'ipNumberPi': u'192.168.1.22', u'piUpToDate': [], u'piDevId': 25018397, u'deltaTime2': 0.3365211486816406, u'output': {u'display': {u'1514723531': [{u'i2cAddress': u'60'}, {u'devType': u'screen'}]}}, u'userIdPi': u'pi', u'rPiVersion': 0, u'deltaTime1': 0.08419489860534668, u'lastMessage': 1507591753.015342, u'enableRebootCheck': u'restartLoop,-', u'passwordPi': u'karl123.', u'input': {u'Wire18B20': {u'137345691': u''}, u'BLEconnect': {u'65802248': u'18:65:90:6A:B9:0D'}, u'i2cOPT3001': {u'1497048646': u''}, u'i2cBMExx': {u'1336842918': u''}, u'DHTxx': {u'1815353069': u''}, u'i2cTSL2561': {u'864053974': u''}}, u'enableiBeacons': u'1', u'sensorRefreshSecs': 20, u'deltaChangedSensor': 5, u'piMAC': u'00:1A:7D:DA:71:14'}
18:29:13                     -in Line '9567' has error='UnexpectedNullError -- CClientMgr not created'
18:29:13                     -warning, ignoring state update: in Line '11448' has error='UnexpectedNullError -- CClientMgr not created'
18:29:13                     -in Line '756' has error='UnexpectedNullError'
18:29:13                     -in Line '8062' has error='UnexpectedNullError -- CClientMgr not created'
18:29:13                     - pi0  RPI{u'ipNumberPiSendTo': u'192.168.1.20', u'sendToIndigoSecs': u'90.0', u'piNumberReceived': u'0', u'sensorList': u'INPUTgpio-1*266587410,i2cBMExx*1491353324*118,BLEsensor*244991166,BLEconnect*65802248,BLEconnect*142616409,BLEconnect*462988504,i2cOPT3001*999157650*68,', u'piOnOff': u'1', u'ipNumberPi': u'192.168.1.20', u'piUpToDate': [], u'piDevId': 1477958849, u'deltaTime2': 0.7487449645996094, u'output': {u'setTEA5767': {u'1800415532': [{u'i2cAddress': u'96'}, {u'devType': u''}]}, u'OUTPUTgpio-1-ONoff': {u'1964742022': [{u'gpio': u'26', u'initialValue': u'up', u'outType': u'0'}]}, u'neopixel': {u'246403135': u''}, u'OUTPUTgpio-1': {u'1752078745': [{u'gpio': u'21', u'initialValue': u'up', u'outType': u'0'}]}, u'OUTPUTgpio-4': {u'567118407': [{u'gpio': u'21', u'initialValue': u'x', u'outType': u'0'}, {u'gpio': u'20', u'initialValue': u'x', u'outType': u'0'}, {u'gpio': u'16', u'initialValue': u'-', u'outType': u'0'}, {u'gpio': u'12', u'initialValue': u'x', u'outType': u'0'}]}, u'display': {u'146308284': [{u'i2cAddress': u'60'}, {u'devType': u'st7735'}], u'1160879538': u'', u'1040812751': [{u'i2cAddress': u'60'}, {u'devType': u'screen'}], u'748719371': [{u'i2cAddress': u'39'}, {u'devType': u'LCD1602'}]}}, u'userIdPi': u'pi', u'rPiVersion': 0, u'deltaTime1': 0.03413701057434082, u'lastMessage': 1507591753.855757, u'enableRebootCheck': u'restartLoop,-', u'passwordPi': u'karl123.', u'input': {u'INPUTgpio-1': {u'688656134': [{u'count': u'off', u'gpio': u'21', u'inpType': u'low'}], u'266587410': [{u'count': u'off', u'gpio': u'16', u'inpType': u'high'}]}, u'i2cBMExx': {u'1491353324': u''}, u'BLEsensor': {u'244991166': u''}, u'BLEconnect': {u'65802248': u'18:65:90:6A:B9:0D', u'142616409': u'FC:E9:98:49:BB:E9', u'462988504': u'AC:29:3A:EC:A9:9F'}, u'i2cOPT3001': {u'999157650': u''}}, u'enableiBeacons': u'1', u'sensorRefreshSecs': 20, u'deltaChangedSensor': 5, u'piMAC': u'5C:F3:70:6D:DA:7A'}
18:29:13                     -in Line '9567' has error='UnexpectedNullError -- CClientMgr not created'


Code: Select all
the code for fist error:
 
try:
...
line 8062 is
            dev = indigo.devices[self.RPI[unicode(pi)]["piDevId"]]
....

        except  Exception, e:
                self.ML.myLog("all", u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
                self.ML.myLog("all", u" pi" + unicode(pi)+"  RPI"+ unicode(self.RPI[unicode(pi)]) )


with
self.ML.myLog(
is
Code: Select all
######################################################################################
# .logfile handling
######################################################################################
import indigo
import os
import sys
import datetime
import time



class MLX():

    def __init__(self):
        self.logFile        = ""
        self.logFileActive  = False
        self.debugLevel     = "all"
        self.maxFileSize    = 20000000
        self.lastCheck      = time.time()


####-----------------  set paramete rs ---------
    def myLogSet(self, **kwargs ):# eg (debugLevel = "abc",logFileActive=True/False ,logFile = "pathToLogFile",  maxFileSize = 10000000)
        for key, value in kwargs.iteritems():
            try:
                if key == "logFileActive":
                    self.logFileActive    = value
           
                elif key == "logFile":
                    self.logFile    = value
           
                elif key == "debugLevel":
                    self.debugLevel     = value

                elif key == "maxFileSize" :
                    self.maxFileSize     = int(value)
                   
            except  Exception, e:
                if len(unicode(e)) > 5:
                    indigo.server.log(u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))


    def myLog(self, msgLevel, text, type=""):
   
        if msgLevel == "" and self.debugLevel != "all": return
   
        if  time.time() - self.lastCheck > 100:
             self.checkLogFiles()

        try:
            if not self.logFileActive:
                if msgLevel == "smallErr":
                    indigo.server.log(u"------------------------------------------------------------------------------")
                    indigo.server.log(text)
                    indigo.server.log(u"------------------------------------------------------------------------------")
                    return

                if msgLevel == "bigErr":
                    indigo.server.log(u"==================================================================================")
                    indigo.server.log(text)
                    indigo.server.log(u"==================================================================================")
                    return

                if msgLevel == "all" or self.debugLevel.find("all") > -1 or self.debugLevel.find(msgLevel) >-1:
                    if type == "":
                        indigo.server.log(text)
                    else:
                        indigo.server.log(text, type=type)
                    return

                return


            else: # print to external logfile

                try:
                    if len(self.logFile) < 3: return # not properly defined
                    f =  open(self.logFile,"a")
                except  Exception, e:
                    indigo.server.log(u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
                    try:
                        f.close()
                    except:
                        pass
                    return
                if msgLevel == "all" or self.debugLevel.find("all") > -1 or self.debugLevel.find(msgLevel) >-1:
                    ts = datetime.datetime.now().strftime("%H:%M:%S")
                    if type == u"":
                        f.write((ts+u" "+u" ".ljust(20) +u"-" + text + u"\n").encode("utf8"))
                    else:
                        f.write((ts+" " +type.ljust(20) +u"-" + text + u"\n").encode("utf8"))
                    f.close()
                    return

                if msgLevel == "smallErr":
                    ts = datetime.datetime.now().strftime("%H:%M:%S")
                    f.write(u"----------------------------------------------------------------------------------\n")
                    f.write((ts+u" ".ljust(12)+u"-"+text+u"\n").encode("utf8"))
                    f.write(u"----------------------------------------------------------------------------------\n")
                    f.close()
                    return

                if msgLevel == "bigErr":
                    ts = datetime.datetime.now().strftime("%H:%M:%S")
                    f.write(u"==================================================================================\n")
                    f.write((ts+u" "+u" ".ljust(12)+u"-"+text+u"\n").encode("utf8"))
                    f.write(u"==================================================================================\n")
                    f.close()
                    return

                return

        except  Exception, e:
            if len(unicode(e)) > 5:
                indigo.server.log(u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
                indigo.server.log(text)
                try: f.close()
                except: pass



Re: how to call a method in the plugin class

PostPosted: Mon Oct 09, 2017 6:08 pm
by kw123
after restarting ~ 20 times i finally got some red lines in the log file:

Code: Select all
      Reloading plugin "piBeacon 7.67.153"
   Stopping plugin "piBeacon 7.67.153" (pid 32520)
   Script Error                    embedded script: HandlerError -- all request handlers are disabled
   Script Error                    Exception Traceback (most recent call shown last):

     embedded script, line 9, at top level
StandardError: HandlerError -- all request handlers are disabled

   Stopped plugin "piBeacon 7.67.153"
   Starting plugin "piBeacon 7.67.153" (pid 32735)


Re: how to call a method in the plugin class

PostPosted: Mon Oct 09, 2017 6:09 pm
by matt (support)
I don't see any messages in there from Indigo Server saying it is trying to (or failing/succeeding) in shutting down the plugin. I'm interested in seeing everything that is logged (from plugin, Indigo Server, etc.).

Re: how to call a method in the plugin class

PostPosted: Mon Oct 09, 2017 6:12 pm
by matt (support)
Okay, that makes a bit more sense. It sounds like you have an embedded python script trying to communicate with your plugin? This error:

embedded script: HandlerError -- all request handlers are disabled

I think is because the embedded script is trying to communicate with the plugin which has already started shutting down. I'm not sure there is much that can be done about that. But the error is coming from the embedded script, not the plugin.

Re: how to call a method in the plugin class

PostPosted: Mon Oct 09, 2017 7:03 pm
by kw123
only things I have that are constant running:

2 classes:
A. for logging
B. tcp/ip stack .

some external scripts (Popen() for expect to communicate via ssh ) but they run may be once an hour.

..
just tested: . if I use the indigo log in my logger class and NOT writing to an external file , there are NO errors..
but writing to a file instead of calling indigo.server.log SHOULD not do anything??

it is this section that is active:
Code: Select all
           else: # print to external logfile

                try:
                    if len(self.logFile) < 3: return # not properly defined
                    f =  open(self.logFile,"a")
                except  Exception, e:
                    indigo.server.log(u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
                    try:
                        f.close()
                    except:
                        pass
                    return
                if msgLevel == "all" or self.debugLevel.find("all") > -1 or self.debugLevel.find(msgLevel) >-1:
                    ts = datetime.datetime.now().strftime("%H:%M:%S")
                    if type == u"":
                        f.write((ts+u" "+u" ".ljust(20) +u"-" + text + u"\n").encode("utf8"))
                    else:
                        f.write((ts+" " +type.ljust(20) +u"-" + text + u"\n").encode("utf8"))
                    f.close()
                    return

                if msgLevel == "smallErr":
                    ts = datetime.datetime.now().strftime("%H:%M:%S")
                    f.write(u"----------------------------------------------------------------------------------\n")
                    f.write((ts+u" ".ljust(12)+u"-"+text+u"\n").encode("utf8"))
                    f.write(u"----------------------------------------------------------------------------------\n")
                    f.close()
                    return

                if msgLevel == "bigErr":
                    ts = datetime.datetime.now().strftime("%H:%M:%S")
                    f.write(u"==================================================================================\n")
                    f.write((ts+u" "+u" ".ljust(12)+u"-"+text+u"\n").encode("utf8"))
                    f.write(u"==================================================================================\n")
                    f.close()
                    return

                return


I really don't see anything that is wrong.. and it only happens when the tcpio stack is active..

..??

Karl

Re: how to call a method in the plugin class

PostPosted: Mon Oct 09, 2017 9:37 pm
by kw123
ok this might be it:

this is the loop inside run concurrent ..
Code: Select all
        ########   ------- here the loop starts    --------------
        while self.quitNow == "":
                self.countLoop += 1
                self.sleep(5.)

                if self.countLoop > 5:
                    anyChange= self.periodCheck()
                if self.statusChanged ==1:  self.setGroupStatus()
                if self.statusChanged ==2:  self.setGroupStatus(init=True)

                if self.enableFING == "1":
                    if self.updateFING("loop ") == "break": break
       
        indigo.server.log( u"hello shutting down after While  ...:  loop ")


when restarting the plugin through regular indigo restart command the "hello shutting down after While ...: loop" does not get printed into the log file.
actually no indigo.xxx seems to work after the while loop.
Is this this plugin or in general. I was always under the impression that at the end of while loop one could do some shutdown things..


Karl
when shutting it down through setting self.quitNow = "xx" it prints "hello shutting down after While ...: loop"

Re: how to call a method in the plugin class

PostPosted: Mon Oct 09, 2017 9:42 pm
by kw123
ok I am idiot .. somehow I dropped the try :/ except:

Code: Select all
try:
   while True
except: pass

around the while loop.
that took me 3 days to find !!!!

forget everything above.

all things work again ..

Karl

Re: how to call a method in the plugin class

PostPosted: Tue Oct 10, 2017 3:45 am
by DaveL17
kw123 wrote:
ok I am idiot ..

That's par for the course in my neck of the woods. :)

Re: how to call a method in the plugin class

PostPosted: Tue Oct 10, 2017 11:14 am
by matt (support)
Great – I'm glad you figured it out because I didn't have a clue as to what could be going wrong. :P