code: def test_imap_unordered(pool_4_processes, use_iter):
      def f(args):
          time.sleep(0.1 * random.random())
          index = args[0]
          err_indices = args[1]
          if index in err_indices:
              raise Exception("intentional failure")
          return index
  
      error_indices = [2, 50, 98]
      in_order = []
      num_errors = 0
      if use_iter:
          imap_iterable = iter(
              [(index, error_indices) for index in range(100)]
          )
      else:
          imap_iterable = [
              (index, error_indices) for index in range(100)
          ]
      result_iter = pool_4_processes.imap_unordered(
          f, imap_iterable, chunksize=11
      )
      for i in range(100):
          result = result_iter.next()
          if isinstance(result, Exception):
              in_order.append(True)
              num_errors += 1
          else:
              in_order.append(result == i)
  
      # Check that the results didn't come back all in order.
      # NOTE: this could be flaky if the calls happened to finish in order due
      # to the random sleeps, but it's very unlikely.
      assert not all(in_order)
      assert num_errors == len(error_indices)
  
      with pytest.raises(StopIteration):
          result_iter.next()
  
imports: import os
  import sys
  import platform
  import pytest
  import tempfile
  import time
  import random
  from collections import defaultdict
  import queue
  import math
  import ray
  from ray._private.test_utils import SignalActor
  from ray.util.multiprocessing import Pool, TimeoutError, JoinableQueue
  from ray.util.joblib import register_ray
  from joblib import parallel_backend, Parallel, delayed
label_desc: Use image node_id 21 for calling a global function with example usage: test_imap_unordered(pool_4_processes, use_iter) and returns: index