Skip to content

feat: in job stability #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
Loading