code: def find_worker_env(idx):
      """Construct a command-line environment for the worker
  
      idx - index of the worker, e.g., 0 for the first, 1 for the second...
      """
      newenv = os.environ.copy()
      cp_install = find_spec("cellprofiler")
      if cp_install:
          root_dir = os.path.abspath(
              os.path.join(os.path.dirname(cp_install.origin), "..")
          )
      else:
          root_dir = os.path.abspath(
              os.path.join(os.path.dirname(__file__), "../..")
          )
      added_paths = []
      if "PYTHONPATH" in newenv:
          old_path = newenv["PYTHONPATH"]
          if not any(
              [root_dir == path for path in old_path.split(os.pathsep)]
          ):
              added_paths.append(root_dir)
      else:
          added_paths.append(root_dir)
  
      if hasattr(sys, "frozen"):
          if sys.platform == "darwin":
              # http://mail.python.org/pipermail/pythonmac-sig/2005-April/013852.html
              added_paths += [p for p in sys.path if isinstance(p, str)]
      if "PYTHONPATH" in newenv:
          added_paths.insert(0, newenv["PYTHONPATH"])
      newenv["PYTHONPATH"] = os.pathsep.join([x for x in added_paths])
      if "CP_JDWP_PORT" in newenv:
          del newenv["CP_JDWP_PORT"]
      if "AW_JDWP_PORT" in newenv:
          port = str(int(newenv["AW_JDWP_PORT"]) + idx)
          newenv["CP_JDWP_PORT"] = port
          del newenv["AW_JDWP_PORT"]
      for key in newenv:
          if isinstance(newenv[key], str):
              newenv[key] = newenv[key]
      return newenv
  
file_path: CellProfiler/src/subpackages/core/cellprofiler_core/utilities/analysis.py
imports: import os
  import sys
  import threading
  from importlib.util import find_spec
label_desc: Use image node_id 2 for calling a global function with example usage: find_worker_env(idx) and returns: newenv