def find_recursion(etype, value, records):
 if (not is_recursion_error(etype, value, records)):
  return (len(records), 0)
 records = [r[1:4] for r in records]
 inner_frames = records[(- (len(records) // 4)):]
 frames_repeated = set(inner_frames)
 last_seen_at = {}
 longest_repeat = 0
 i = len(records)
 for frame in reversed(records):
  i -= 1
  if (frame not in frames_repeated):
   last_unique = i
   break
  if (frame in last_seen_at):
   distance = (last_seen_at[frame] - i)
   longest_repeat = max(longest_repeat, distance)
  last_seen_at[frame] = i
 else:
  last_unique = 0
 return (last_unique, longest_repeat)

def find_recursion ( etype , value , records ) : if ( not is_recursion_error ( etype , value , records ) ) : return ( len ( records ) , 0 ) records = [ r [ 1 : 4 ] for r in records ] inner_frames = records [ ( - ( len ( records ) // 4 ) ) : ] frames_repeated = set ( inner_frames ) last_seen_at = { } longest_repeat = 0 i = len ( records ) for frame in reversed ( records ) : i -= 1 if ( frame not in frames_repeated ) : last_unique = i break if ( frame in last_seen_at ) : distance = ( last_seen_at [ frame ] - i ) longest_repeat = max ( longest_repeat , distance ) last_seen_at [ frame ] = i else : last_unique = 0 return ( last_unique , longest_repeat )
identify the repeating stack frames from a recursionerror traceback records is a list as returned by verbosetb .