Skip to content

Commit

Permalink
doc-string
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed Apr 29, 2024
1 parent 9e67fbe commit 2e47c45
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions adaptive_scheduler/_scheduler/slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,31 @@ def partitions(self) -> dict[str, int]:

@staticmethod
def cancel_jobs(name: str, *, dry: bool = False) -> None:
"""Cancel the jobs with names matching the pattern '{name}-{i}' where i is an integer."""
"""Cancel jobs with names matching the pattern '{name}-{i}' where i is an integer.
Parameters
----------
name
The base name of the jobs to cancel. Jobs with names that start with '{name}-'
followed by an integer will be canceled.
dry
If True, perform a dry run and print the job IDs that would be canceled without
actually canceling them. Default is False.
Raises
------
RuntimeError
If there is an error while canceling the jobs.
Examples
--------
>>> SLURM.cancel_jobs("my_job")
# Cancels all running jobs with names like "my_job-1", "my_job-2", etc.
>>> SLURM.cancel_jobs("my_job", dry=True)
# Prints the job IDs that would be canceled without actually canceling them.
"""
running_jobs = SLURM.queue()
job_ids_to_cancel = []

Expand All @@ -455,7 +479,9 @@ def cancel_jobs(name: str, *, dry: bool = False) -> None:
subprocess.run(cmd.split(), check=True)
except subprocess.CalledProcessError as e:
msg = f"Failed to cancel jobs with name {name}. Error: {e}"
raise RuntimeError(msg) from e
raise RuntimeError(
msg,
) from e
else:
print(f"No running jobs found with name pattern '{name}-<integer>'")

Expand Down

0 comments on commit 2e47c45

Please sign in to comment.