code: def pickle_with_weak_refs( o ):
      
      if isinstance(o, types.GeneratorType):
          o = [i for i in o]
      walk = dict([ (path,val) for path, val in objwalk(o)])
      for path, val in walk.items():
          if len(path) > MAX_DEPTH or is_lambda(val):
              truncate_attr_at_path(o, path)
          if isinstance(val, weakref.ref):
              setattr_at_path( o, path, val() ) # Resolve weak references
      return pickle.dumps(o)
docs: Pickles an object containing weak references.
  
      :param mixed o: Any object
  
      :rtype str: The pickled object