Skip to content

Commit c27f5f8

Browse files
feat: in job stability (#137)
might increase stability of in-job submissions, might fix #113 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a utility function to manage SLURM environment variables, enhancing job submission reliability. - Updated warning handling to clean up SLURM environments when specific conditions are met. - **Bug Fixes** - Improved resource management by ensuring lingering SLURM job contexts are addressed. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 6dad273 commit c27f5f8

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

snakemake_executor_plugin_slurm/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from snakemake_interface_common.exceptions import WorkflowError
2727
from snakemake_executor_plugin_slurm_jobstep import get_cpus_per_task
2828

29+
from .utils import delete_slurm_environment
30+
2931

3032
@dataclass
3133
class ExecutorSettings(ExecutorSettingsBase):
@@ -85,10 +87,11 @@ def warn_on_jobcontext(self, done=None):
8587
if "SLURM_JOB_ID" in os.environ:
8688
self.logger.warning(
8789
"You are running snakemake in a SLURM job context. "
88-
"This is not recommended, as it may lead to unexpected behavior."
90+
"This is not recommended, as it may lead to unexpected behavior. "
8991
"Please run Snakemake directly on the login node."
9092
)
9193
time.sleep(5)
94+
delete_slurm_environment()
9295
done = True
9396

9497
def additional_general_args(self):
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# utility functions for the SLURM executor plugin
2+
3+
import os
4+
5+
6+
def delete_slurm_environment():
7+
"""
8+
Function to delete all environment variables
9+
starting with 'SLURM_'. The parent shell will
10+
still have this environment. This is needed to
11+
submit within a SLURM job context to avoid
12+
conflicting environments.
13+
"""
14+
for var in os.environ:
15+
if var.startswith("SLURM_"):
16+
del os.environ[var]

0 commit comments

Comments
 (0)