0

I'm trying to use the timeout_decorator. https://github.com/pnpnpn/timeout-decorator

I have the timeout defined else where in the code. I keep getting the following error: NameError: name 'self' is not defined

class rtuCommsLib():

def __init__(self, _mirrorQueue):
    self.CMD_LIST_SET = [ {'cmd' : 'MDM_ON',            'rtuCmd' : 'mdm on',
                           'pass': re.compile(r'([0])|(>[0])'), 'error' : re.compile(r'>[1-9]|[1-9]'),
                           'cmdState' : self.CMD_STATES['NONE'], 'timeout' : '1', 'returnValue' : None },

@timeout_decorator.timeout( self.CMD_LIST_SET[self.cmdIndex]['timeout'], timeout_exception=StopIteration)
def sendCmdWait(self):
    #Wait for command to process
    try:
        while(self.CMD_LIST_SET[self.cmdIndex]['cmdState'] == self.CMD_STATES['WAITING']):
            time.sleep(0.1)
        return "SUCCESS"
    except StopIteration:
        print "Timeout Error"
        return "ERROR"
Diego Aguilera
  • 107
  • 1
  • 7

1 Answers1

0

You are using self variable in the decorator call, but self is not accessible here.

@timeout_decorator.timeout( self.CMD_LIST_SET[self.cmdIndex]['timeout'], timeout_exception=StopIteration)
                            ^^^ here, self is not accessible

You have to find another way to pass arguments or change implementation to access self within the decorator like explained here: Access self from decorator.

Community
  • 1
  • 1
Arount
  • 9,853
  • 1
  • 30
  • 43