# How to run a SLURM job within Python without a hanging command line

When running parameter variation , we want to programmatically adjust SLURM parameters (memory, number of processes, etc) depending on the parameters of the study (mesh density, etc). We don’t want the submission of the job to hang until the job has completed, we want to start everything in parallel.

For this to work without populating stdout with status reports about pending jobs, call(command, shell=True) is necessary. This means the command must be formulated not as a list, but as a single string. See this SO answer. Once the string is defined, at the end of the string redirection to /dev/null is done to supress output and the job is set to the background. The rest is taken care of by SLURM: resource allocation, start, running, everything runs as it was started with a SLURM script.

from subprocess import call