code: def appropriate_imap(
      num_cores: int,
  ) -> tuple[MapLike, ClosableJoinable]:
      if num_cores < 2:
          imap: MapLike = map
  
          # in order to make it simpler to cleanup a pool of processes
          # always return something that we can close and join
  
          pool: ClosableJoinable = MockPool()
      else:
          from .backport import Pool
  
          pool = Pool(processes=num_cores)
          imap = functools.partial(pool.imap_unordered, chunksize=20000)
  
      return imap, pool
  
imports: from __future__ import annotations
  import collections
  import functools
  import itertools
  import multiprocessing
  import multiprocessing.dummy
  import os
  import queue
  import tempfile
  from typing import TYPE_CHECKING, overload
  import numpy
  from dedupe.backport import RLock
label_desc: Use image node_id 4 for calling a global function with example usage: appropriate_imap(num_cores) and returns: imap,  pool