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