Ich versuche, den timeout_decorator zu verwenden. https://github.com/pnpnpn/timeout-decoratorPython timeout_decorator Zeitüberschreitung
Ich habe das Timeout sonst wo im Code definiert. Ich erhalte den folgenden Fehler: NameError: name 'self' is not defined
Klasse 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"