當我嘗試使用600個測試運行智能卡測試工具的主機程序時,我不斷收到此錯誤「RuntimeError:調用Python對象時超出最大遞歸深度」,並且在第300次測試,我嘗試了「sys.setrecursionlimit(10000)」,並解決了這個問題,但我確實知道這不是解決這個錯誤的最好方法,我該如何更改我的代碼,以免碰到這個問題錯誤:runtimeerror:最大遞歸深度超過python
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.SndRcv'調用'self.processResponse','self.processResponse'調用'self.SndRcv'。你能看到爲什麼會導致任意深度遞歸? –
要理解遞歸,您首先需要了解遞歸... – moooeeeep
擴大一點:'''SndRcv'''永遠不會返回,'processResponse''只會返回'''如果ciMsgType是None''。 – wwii