code: def persist(model, *, method=None):
      """
      Persist a model for cross-process sharing.
  
      This will return a persisted model that can be used to reconstruct the model
      in a worker process (using :meth:`PersistedModel.get`).
  
      If no method is provided, this function automatically selects a model persistence
      strategy from the the following, in order:
  
      1. If `LK_TEMP_DIR` is set, use :mod:`binpickle` in shareable mode to save
         the object into the LensKit temporary directory.
      2. If :mod:`multiprocessing.shared_memory` is available, use :mod:`pickle`
         to save the model, placing the buffers into shared memory blocks.
      3. Otherwise, use :mod:`binpickle` in shareable mode to save the object
         into the system temporary directory.
  
      Args:
          model(obj):
              The model to persist.
          method(str or None):
              The method to use.  Can be one of ``binpickle`` or ``shm``.
  
      Returns:
          PersistedModel: The persisted object.
      """
      if method is not None:
          if method == "binpickle":
              method = persist_binpickle
          elif method == "shm":
              method = persist_shm
          elif not hasattr(method, "__call__"):
              raise ValueError(
                  "invalid method %s: must be one of binpickle, shm, or a funciton"
              )
  
      if method is None:
          if SHM_AVAILABLE and "LK_TEMP_DIR" not in os.environ:
              method = persist_shm
          else:
              method = persist_binpickle
  
      return method(model)
  
file_path: lkpy/lenskit/sharing/__init__.py
imports: import os
  import warnings
  from abc import abstractmethod, ABC
  from contextlib import contextmanager
  import threading
  import logging
  from .binpickle import persist_binpickle, BPKPersisted
  from .shm import persist_shm, SHMPersisted, SHM_AVAILABLE
label_desc: Use image node_id 4 for calling a global function with example usage: persist(model) and returns: method