code: def run_in_subprocess(func, *args, **kwargs):
      """
      Run some code in a separate process and return the result. Once the code is done, terminate the process.
      This prevents a memory leak in the other process from affecting the current process.
  
      Gotcha: func must be a functioned defined at the top level of the module.
      :param kwargs: dict
      :param args: list
      :param func:
      :return:
      """
      pool = Pool(1)
      result = pool.apply(func, args=args, kwds=kwargs)
  
      # Probably not strictly necessary since terminate is called on GC, but it's not guaranteed when the pool will get
      # GC'd.
      pool.terminate()
      return result
  
file_path: petastorm/petastorm/utils.py
imports: import logging
  import os
  from decimal import Decimal
  from multiprocessing import Pool
  import numpy
  import pyarrow
  from future.utils import raise_with_traceback
  from pyarrow.filesystem import LocalFileSystem
label_desc: Use image node_id 1 for calling a global function with example usage: run_in_subprocess(func) and returns: result