Skip to content

Commit 79f430f

Browse files
committed
Pass a bash script to sbatch rather than the command directly to circumvent SLURM command-line character limit
1 parent a3e91cd commit 79f430f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

snakemake_executor_plugin_slurm/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,19 +500,21 @@ def run_job(self, job: JobExecutorInterface):
500500

501501
exec_job = self.format_job_exec(job)
502502

503-
# and finally the job to execute with all the snakemake parameters
504-
call += f' --wrap="{exec_job}"'
503+
# format the job to execute with all the snakemake parameters into a shell script
504+
sbatch_script = "\n".join(["#!/bin/sh", exec_job])
505505

506506
self.logger.debug(f"sbatch call: {call}")
507+
self.logger.debug(f"sbatch script:\n{sbatch_script}")
507508
try:
508509
process = subprocess.Popen(
509-
call,
510+
f"{call} /dev/stdin", # tell sbatch to read the sbatch script from stdin
510511
shell=True,
511512
text=True,
513+
stdin=subprocess.PIPE,
512514
stdout=subprocess.PIPE,
513515
stderr=subprocess.PIPE,
514516
)
515-
out, err = process.communicate()
517+
out, err = process.communicate(input=sbatch_script) # feed the sbatch shell script through stdin
516518
if process.returncode != 0:
517519
raise subprocess.CalledProcessError(
518520
process.returncode, call, output=err
@@ -524,6 +526,7 @@ def run_job(self, job: JobExecutorInterface):
524526
"SLURM sbatch failed. "
525527
f"The error message was '{e.output.strip()}'.\n"
526528
f" sbatch call:\n {call}\n"
529+
f" sbatch script:\n{sbatch_script}\n"
527530
),
528531
)
529532
return

0 commit comments

Comments
 (0)