Skip to content

Commit

Permalink
feat: in job stability (#137)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cmeesters and coderabbitai[bot] authored Aug 23, 2024
1 parent 6dad273 commit c27f5f8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion snakemake_executor_plugin_slurm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
16 changes: 16 additions & 0 deletions snakemake_executor_plugin_slurm/utils.py
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit c27f5f8

Please sign in to comment.