class_docstr: A context manager to enable CPU affinity for data loader workers
  (only used when running on CPU devices).
  
  Affinitization places data loader workers threads on specific CPU cores.
  In effect, it allows for more efficient local memory allocation and reduces
  remote memory calls.
  Every time a process or thread moves from one core to another, registers
  and caches need to be flushed and reloaded.
  This can become very costly if it happens often, and our threads may also
  no longer be close to their data, or be able to share data in a cache.
  
  See `here <https://pytorch-geometric.readthedocs.io/en/latest/advanced/
  cpu_affinity.html>`__ for the accompanying tutorial.
  
  .. warning::
  
      To correctly affinitize compute threads (*i.e.* with
      :obj:`KMP_AFFINITY`), please make sure that you exclude
      :obj:`loader_cores` from the list of cores available for the main
      process.
      This will cause core oversubsription and exacerbate performance.
  
  .. code-block:: python
  
      loader = NeigborLoader(data, num_workers=3)
      with loader.enable_cpu_affinity(loader_cores=[0, 1, 2]):
          for batch in loader:
              pass
code: def _aff_init_fn(self, worker_id: int) -> None:
      try:
          worker_cores = self.loader_cores[worker_id]
          if not isinstance(worker_cores, List):
              worker_cores = [worker_cores]
  
          if torch.multiprocessing.get_context()._name == "spawn":
              torch.set_num_threads(len(worker_cores))
  
          psutil.Process().cpu_affinity(worker_cores)
  
      except IndexError:
          raise ValueError(
              f"Cannot use CPU affinity for worker ID "
              f"{worker_id} on CPU {self.loader_cores}"
          )
  
      # Chain worker init functions:
      self._old_worker_init_fn(worker_id)
  
imports: import glob
  import logging
  import os
  import os.path
  import warnings
  from contextlib import contextmanager
  from typing import Any, Callable, Dict, List, Optional, Union
  import psutil
  import torch
  from torch_geometric.data import HeteroData
label_desc: Use image node_id 1 for calling the AffinityMixin obj's underlying member method code with example usage: obj._aff_init_fn(worker_id) without return types