code: def optional_threaded_foreach(
      target: Callable,
      args_iterable: Iterable[Tuple],
      multithreaded: bool,
  ):
      """
      Applies 'target' function to each Tuple args in 'args_iterable'.
      If 'multithreaded' a thread is spawned for each function application.
  
      Args:
          target (Callable):
              A function that takes as input the parameters in each args_iterable Tuple.
  
          args_iterable (Iterable[Tuple]):
              An iterable of the tuples each containing a set of parameters to pass to
              target.
  
          multithreaded (bool):
              Whether or not the target applications are parallelized by thread.
      """
  
      if multithreaded:
          threads = []
          for args in args_iterable:
              thread = threading.Thread(target=target, args=args)
              thread.start()
              threads.append(thread)
  
          for t in threads:  # Wait for all threads to complete
              t.join()
      else:
          for args in args_iterable:
              target(*args)
  
imports: from __future__ import annotations
  import csv
  import itertools
  import logging
  import math
  import sys
  import threading
  from collections import defaultdict
  from dataclasses import Field, field, fields
  from fractions import Fraction
  from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
  import av
  import numpy
  import torch
  from iopath.common.file_io import g_pathmgr
label_desc: Use image node_id 5 for calling a global function with example usage: optional_threaded_foreach(target, args_iterable, multithreaded) without return types