docs: def recursion_depth(key):
      """
      A context manager used to guard recursion depth for some function.
      Multiple functions can be kept separately because it will be
      counted per key.
  
      Any exceptions raise in the recursive function will reset the counter,
      because the stack will be unwinded.
  
      usage::
  
          with recursion_depth('some_function_name') as recursion_level:
              if recursion_level > getattr(settings, 'RECURSION_LIMIT', sys.getrecursionlimit() / 10):
                  raise Exception("Too deep")
  
              # do some recursive dangerous things.
  
      :param key: The key under which the recursion depth is kept.
      """
      try:
          if not getattr(RECURSION_LEVEL_DICT, 'key', False):
              RECURSION_LEVEL_DICT.key = 0
          RECURSION_LEVEL_DICT.key += 1
          yield RECURSION_LEVEL_DICT.key
          RECURSION_LEVEL_DICT.key -= 1
      except Exception as e:
          RECURSION_LEVEL_DICT.key = 0
          raise e