code: def parallel_imap_unordered(
      func, iterable, max_parallel=None, dir=None
  ):
      if max_parallel is None:
          # Lazy import to save on startup time for metaflow as a whole
          from multiprocessing import cpu_count
  
          max_parallel = cpu_count()
  
      args_iter = iter(iterable)
      pids = [
          _spawn(func, arg, dir)
          for arg in islice(args_iter, max_parallel)
      ]
  
      while pids:
          for idx, pid_info in enumerate(pids):
              pid, output_file = pid_info
              pid, exit_code = os.waitpid(pid, os.WNOHANG)
              if pid:
                  pids.pop(idx)
                  break
          else:
              time.sleep(0.1)  # Wait a bit before re-checking
              continue
  
          if exit_code:
              raise MulticoreException("Child failed")
  
          with open(output_file, "rb") as f:
              yield pickle.load(f)
          os.remove(output_file)
  
          arg = list(islice(args_iter, 1))
          if arg:
              pids.insert(0, _spawn(func, arg[0], dir))
  
file_path: metaflow/metaflow/multicore_utils.py
imports: import sys
  import os
  import traceback
  from itertools import islice
  from tempfile import NamedTemporaryFile
  import time
  import metaflow.tracing
label_desc: Use image node_id 2 for calling a global function with example usage: parallel_imap_unordered(func, iterable, max_parallel, dir) without return types