code: def set_loky_pickler(loky_pickler=None):
      global _LokyPickler, _loky_pickler_name
  
      if loky_pickler is None:
          loky_pickler = ENV_LOKY_PICKLER
  
      loky_pickler_cls = None
  
      # The default loky_pickler is cloudpickle
      if loky_pickler in ["", None]:
          loky_pickler = "cloudpickle"
  
      if loky_pickler == _loky_pickler_name:
          return
  
      if loky_pickler == "cloudpickle":
          from joblib.externals.cloudpickle import (
              CloudPickler as loky_pickler_cls,
          )
      else:
          try:
              from importlib import import_module
  
              module_pickle = import_module(loky_pickler)
              loky_pickler_cls = module_pickle.Pickler
          except (ImportError, AttributeError) as e:
              extra_info = (
                  "\nThis error occurred while setting loky_pickler to"
                  f" '{loky_pickler}', as required by the env variable "
                  "LOKY_PICKLER or the function set_loky_pickler."
              )
              e.args = (e.args[0] + extra_info,) + e.args[1:]
              e.msg = e.args[0]
              raise e
  
      util.debug(
          f"Using '{loky_pickler if loky_pickler else 'cloudpickle'}' for "
          "serialization."
      )
  
      class CustomizablePickler(loky_pickler_cls):
          _loky_pickler_cls = loky_pickler_cls
  
          def _set_dispatch_table(self, dispatch_table):
              for ancestor_class in self._loky_pickler_cls.mro():
                  dt_attribute = getattr(
                      ancestor_class, "dispatch_table", None
                  )
                  if isinstance(
                      dt_attribute, types.MemberDescriptorType
                  ):
                      # Ancestor class (typically _pickle.Pickler) has a
                      # member_descriptor for its "dispatch_table" attribute. Use
                      # it to set the dispatch_table as a member instead of a
                      # dynamic attribute in the __dict__ of the instance,
                      # otherwise it will not be taken into account by the C
                      # implementation of the dump method if a subclass defines a
                      # class-level dispatch_table attribute as was done in
                      # cloudpickle 1.6.0:
                      # https://github.com/joblib/loky/pull/260
                      dt_attribute.__set__(self, dispatch_table)
                      break
  
              # On top of member descriptor set, also use setattr such that code
              # that directly access self.dispatch_table gets a consistent view
              # of the same table.
              self.dispatch_table = dispatch_table
  
          def __init__(
              self, writer, reducers=None, protocol=HIGHEST_PROTOCOL
          ):
              loky_pickler_cls.__init__(self, writer, protocol=protocol)
              if reducers is None:
                  reducers = {}
  
              if hasattr(self, "dispatch_table"):
                  # Force a copy that we will update without mutating the
                  # any class level defined dispatch_table.
                  loky_dt = dict(self.dispatch_table)
              else:
                  # Use standard reducers as bases
                  loky_dt = copyreg.dispatch_table.copy()
  
              # Register loky specific reducers
              loky_dt.update(_dispatch_table)
  
              # Set the new dispatch table, taking care of the fact that we
              # need to use the member_descriptor when we inherit from a
              # subclass of the C implementation of the Pickler base class
              # with an class level dispatch_table attribute.
              self._set_dispatch_table(loky_dt)
  
              # Register the reducers
              for type, reduce_func in reducers.items():
                  self.register(type, reduce_func)
  
          def register(self, type, reduce_func):
              """Attach a reducer function to a given type in the dispatch table."""
              self.dispatch_table[type] = reduce_func
  
      _LokyPickler = CustomizablePickler
      _loky_pickler_name = loky_pickler
  
file_path: catboost/contrib/python/joblib/joblib/externals/loky/backend/reduction.py
imports: import copyreg
  import io
  import functools
  import types
  import sys
  import os
  from multiprocessing import util
  from pickle import loads, HIGHEST_PROTOCOL
label_desc: Use image node_id 5 for calling a global function with example usage: set_loky_pickler(loky_pickler) without return types