code: def multi_write_image(
      data: np.ndarray,
      path_template: str,
      write_fn=write_png,
      max_write_threads=16,
      **kwargs,
  ):
      """Write a batch of images to a series of files using a ThreadPool.
      Args:
        data: Batch of images to write. Shape = (batch_size, height, width, channels)
        path_template: a template for the filenames (e.g. "rgb_frame_{:05d}.png").
          Will be formatted with the index of the image.
        write_fn: the function used for writing the image to disk.
          Must take an image array as its first and a filename as its second argument.
          May take other keyword arguments. (Defaults to the write_png function)
        max_write_threads: number of threads to use for writing images. (default = 16)
        **kwargs: additional kwargs to pass to the write_fn.
      """
      num_threads = min(data.shape[0], max_write_threads)
      with multiprocessing.pool.ThreadPool(num_threads) as pool:
          args = [
              (img, path_template.format(i))
              for i, img in enumerate(data)
          ]
  
          def write_single_image_fn(arg):
              write_fn(*arg, **kwargs)
  
          for result in pool.imap_unordered(
              write_single_image_fn, args
          ):
              if isinstance(result, Exception):
                  logger.warning(
                      "Exception while writing image %s", result
                  )
  
          pool.close()
          pool.join()
  
imports: import contextlib
  import functools
  import logging
  import json
  import multiprocessing
  import pickle
  from typing import Any, Dict
  from etils import epath
  import imageio
  import numpy
  import png
  import tensorflow
  from kubric import plotting
  from kubric.kubric_typing import PathLike
label_desc: Use image node_id 12 for calling a global function with example usage: multi_write_image(data, path_template, write_fn, max_write_threads) without return types