code: def clean_env() -> tp.Iterator[None]:
      """Removes slurm and submitit related environment variables so as to avoid interferences
      when submiting a new job from a job.
  
      Note
      ----
      A slurm job submitted from within a slurm job inherits some of its attributes, which may
      be confusing a cause weird gres errors (or pytorch distributed).
      Submitting within this context should prevent this.
  
      Usage
      -----
      with submitit.helpers.clean_env():
          executor.submit(...)
      """
      distrib_names = (
          "MASTER_ADDR",
          "MASTER_PORT",
          "RANK",
          "WORLD_SIZE",
          "LOCAL_RANK",
          "LOCAL_WORLD_SIZE",
      )
      cluster_env = {
          x: os.environ.pop(x)
          for x in os.environ
          if x.startswith(
              ("SLURM_", "SLURMD_", "SRUN_", "SBATCH_", "SUBMITIT_")
          )
          or x in distrib_names
      }
      try:
          yield
      finally:
          os.environ.update(cluster_env)
  
imports: import collections
  import contextlib
  import datetime
  import itertools
  import os
  import random
  import shutil
  import subprocess
  import tempfile
  import time
  import typing
  from pathlib import Path
  from .core import core
  from .core.job_environment import JobEnvironment
  from .core.utils import CommandFunction
  from .core.utils import DelayedSubmission
  from .core.utils import environment_variables
label_desc: Use image node_id 5 for calling a global function with example usage: clean_env() without return types