diff --git a/snakemake_executor_plugin_slurm/__init__.py b/snakemake_executor_plugin_slurm/__init__.py index a39936b1..5b25540c 100644 --- a/snakemake_executor_plugin_slurm/__init__.py +++ b/snakemake_executor_plugin_slurm/__init__.py @@ -26,6 +26,8 @@ from snakemake_interface_common.exceptions import WorkflowError from snakemake_executor_plugin_slurm_jobstep import get_cpus_per_task +from .utils import delete_slurm_environment + @dataclass class ExecutorSettings(ExecutorSettingsBase): @@ -85,10 +87,11 @@ def warn_on_jobcontext(self, done=None): if "SLURM_JOB_ID" in os.environ: self.logger.warning( "You are running snakemake in a SLURM job context. " - "This is not recommended, as it may lead to unexpected behavior." + "This is not recommended, as it may lead to unexpected behavior. " "Please run Snakemake directly on the login node." ) time.sleep(5) + delete_slurm_environment() done = True def additional_general_args(self): diff --git a/snakemake_executor_plugin_slurm/utils.py b/snakemake_executor_plugin_slurm/utils.py new file mode 100644 index 00000000..50eb1f45 --- /dev/null +++ b/snakemake_executor_plugin_slurm/utils.py @@ -0,0 +1,16 @@ +# utility functions for the SLURM executor plugin + +import os + + +def delete_slurm_environment(): + """ + Function to delete all environment variables + starting with 'SLURM_'. The parent shell will + still have this environment. This is needed to + submit within a SLURM job context to avoid + conflicting environments. + """ + for var in os.environ: + if var.startswith("SLURM_"): + del os.environ[var]