code: def try_serialize_handler(handler):
    
    if (isinstance(handler, types.InstanceType) or  # old style class
        (isinstance(handler, object) and  # new style class
         not inspect.isfunction(handler) and
         not inspect.ismethod(handler)) and
        hasattr(handler, "__call__")):
      return pickle.dumps(handler)
    return None
docs: Try to serialize map/reduce handler.
  
    Args:
      handler: handler function/instance. Handler can be a function or an
        instance of a callable class. In the latter case, the handler will
        be serialized across slices to allow users to save states.
  
    Returns:
      serialized handler string or None.