class_docstr: A context manager to enable multi-threading in
  :class:`~torch.utils.data.DataLoader` workers.
  It changes the default value of threads used in the loader from :obj:`1`
  to :obj:`worker_threads`.
docstr: Enables multithreading in worker subprocesses.
  This option requires to change the start method from :obj:`"fork"` to
  :obj:`"spawn"`.
  
  .. code-block:: python
  
      def run():
          loader = NeigborLoader(data, num_workers=3)
          with loader.enable_multithreading(10):
              for batch in loader:
                  pass
  
      if __name__ == '__main__':
          torch.set_start_method('spawn')
          run()
  
  Args:
      worker_threads (int, optional): The number of threads to use in
          each worker process.
          By default, it uses half of all available CPU cores.
          (default: :obj:`torch.get_num_threads() // num_workers`)
docstr_tok: ["Enables","multithreading","in","worker","subprocesses",".","This","option","requires","to","change","the","start","method","from",":","obj",":","`","``","fork","''","`","to",":","obj",":","`","``","spawn","''","`",".","..","code-block",":",":","python","def","run","(",")",":","loader","=","NeigborLoader","(","data",",","num_workers=3",")","with","loader.enable_multithreading","(","10",")",":","for","batch","in","loader",":","pass","if","__name__","==","'__main__","'",":","torch.set_start_method","(","'spawn","'",")","run","(",")","Args",":","worker_threads","(","int",",","optional",")",":","The","number","of","threads","to","use","in","each","worker","process",".","By","default",",","it","uses","half","of","all","available","CPU","cores",".","(","default",":",":","obj",":","`","torch.get_num_threads","(",")","\/\/","num_workers","`",")"]
code: def enable_multithreading(
      self,
      worker_threads: Optional[int] = None,
  ) -> None:
      r"""Enables multithreading in worker subprocesses.
      This option requires to change the start method from :obj:`"fork"` to
      :obj:`"spawn"`.
  
      .. code-block:: python
  
          def run():
              loader = NeigborLoader(data, num_workers=3)
              with loader.enable_multithreading(10):
                  for batch in loader:
                      pass
  
          if __name__ == '__main__':
              torch.set_start_method('spawn')
              run()
  
      Args:
          worker_threads (int, optional): The number of threads to use in
              each worker process.
              By default, it uses half of all available CPU cores.
              (default: :obj:`torch.get_num_threads() // num_workers`)
      """
      if worker_threads is None:
          worker_threads = torch.get_num_threads() // self.num_workers
  
      self._worker_threads = worker_threads
  
      if not self.num_workers > 0:
          raise ValueError(
              f"'enable_multithreading' needs to be performed "
              f"with at least one worker "
              f"(got {self.num_workers})"
          )
  
      if worker_threads > torch.get_num_threads():
          raise ValueError(
              f"'worker_threads' should be smaller than the "
              f"total available number of threads "
              f"{torch.get_num_threads()} "
              f"(got {worker_threads})"
          )
  
      context = torch.multiprocessing.get_context()._name
      if context != "spawn":
          raise ValueError(
              f"'enable_multithreading' can only be used with "
              f"the 'spawn' multiprocessing context "
              f"(got {context})"
          )
  
      self._old_worker_init_fn = WorkerInitWrapper(self.worker_init_fn)
      try:
          logging.debug(
              f"Using {worker_threads} threads in each worker"
          )
          self.worker_init_fn = self._mt_init_fn
          yield
      finally:
          self.worker_init_fn = self._old_worker_init_fn
  
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 2 for calling the MultithreadingMixin obj's underlying member method code with example usage: obj.enable_multithreading(worker_threads) without return types