code: def run_in_process_group(filename: str, calls: List[Dict[str, Any]]):
      if torch.distributed.is_initialized():
          torch.distributed.destroy_process_group()
      processes = []
      q = Queue()
      wait_event = Event()
  
      # run the remaining processes
      # for rank in range(world_size - 1):
      for rank, call in enumerate(calls):
          p = Process(
              target=init_and_run_process,
              args=(
                  rank,
                  call["world_size"],
                  filename,
                  call["function"],
                  call["inputs"],
                  q,
                  wait_event,
              ),
          )
          p.start()
          processes.append(p)
  
      # fetch the results from the queue before joining, the background processes
      # need to be alive if the queue contains tensors. See
      # https://discuss.pytorch.org/t/using-torch-tensor-over-multiprocessing-queue-process-fails/2847/3  # noqa: B950
      results = []
      for _ in range(len(processes)):
          results.append(q.get())
  
      wait_event.set()
  
      for p in processes:
          p.join()
      return results
  
file_path: ClassyVision/test/generic_distributed_util_test.py
imports: import tempfile
  import unittest
  from itertools import product
  from typing import Any, Dict, List
  import torch
  from classy_vision.generic.distributed_util import _PRIMARY_RANK, broadcast_object
  from torch.multiprocessing import Event, Process, Queue
label_desc: Use image node_id 2 for calling a global function with example usage: run_in_process_group(filename, calls) and returns: results