I keep getting this error"RuntimeError: maximum recursion depth exceeded while calling a Python object" when I try running my host program for smart card test tool with 600 tests and I get this error after the 300th test, I tried "sys.setrecursionlimit(10000)" and that fixed the problem, but I do know that this is not the best way to go about this error, how can I change my code so I don't run into this error:
def SndRcv(self,request):
print ">> ", request
device_api.send(request)
resp = device_api.receive()
print "<< ", resp
self.processResponse(resp)
def processResponse(self, K400Message):
global mWaitingCardRemoval
ciMsg = card_interface_response
ciMsgType = card_interface_response.ci_msg
if ciMsgType is None:
print 'weird, malformed protobuf response'
return
whichMsg = ciMsgType.WhichOneof('msg')
print 'msg = ' + str(whichMsg)
if whichMsg is 'collision':
self.StartSession()
elif whichMsg is 'card_removed':
if ciMsgType.issuer== ci.CARD_INTERFACE_MASK_CxLESS:
mWaitingCardRemoval &= ~(ciMsgType.issuer)
if EndofSession is False:
self.parseMessage()
if mWaitingCardRemoval !=0:
self.parseMessage()
self.StartSession()
elif whichMsg is 'waiting_removal':
if EndofSession is False:
self.parseMessage()
else:
mWaitingCardRemoval |= ciMsgType.issuer
elif whichMsg is 'card_detected':
mode = ciMsgType.issuer
reqMsg = pm.get_Deactivate((ci.CARD_INTERFACE_MASK_ANY)& ~(ciMsgType.issuer))
self.SendOnly(reqMsg)
acceptMsg = pm.get_Activate(mode)
self.SndRcv(acceptMsg)
elif whichMsg is 'card_ready':
self.StartLoop(ciMsgType.issuer)
elif whichMsg is 'rapdu':
self.processCardAPDUResponse(ciMsgType.issuer, ciMsg.data.encode('hex'))
elif whichMsg is 'card_not_responding':
if ciMsgType.issuer == ci.CARD_INTERFACE_MASK_CONTACT:
self.EndCardSession(ciMsgType.issuer,True)
else:
self.EndCardSession(ciMsgType.issuer, False)
elif whichMsg is 'resp_special':
if ciMsg.data.encode('hex') > 0:
logging.info(ciMsg.data.encode('hex'))
else:
logging.info("")
self.SndRcvcallsself.processResponse, andself.processResponsecallsself.SndRcv. Can you see why that can lead to arbitrary depth recursion?SndRcvnever returns andprocessResponseonly returnsif ciMsgType is None.