Skip to content
Snippets Groups Projects
Commit 30184553 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

MNT: New 'silent' option to run function, which is equivalent to passing

log={'tee':false}. When calling run(..., submit=True), any log argument is
passed through to fsl_sub - this means that calling run(..., submit=True,
silent=True) will prevent the job ID from being printed
parent a5260424
No related branches found
No related tags found
No related merge requests found
...@@ -188,6 +188,9 @@ def run(*args, **kwargs): ...@@ -188,6 +188,9 @@ def run(*args, **kwargs):
- cmd: Optional file-like or callable to which - cmd: Optional file-like or callable to which
the command itself is logged. the command itself is logged.
:arg silent: Suppress standard output/error. Equivalent to passing
``log={'tee' : False}``. Ignored if `log` is also passed.
All other keyword arguments are passed through to the ``subprocess.Popen`` All other keyword arguments are passed through to the ``subprocess.Popen``
object (via :func:`_realrun`), unless ``submit=True``, in which case they object (via :func:`_realrun`), unless ``submit=True``, in which case they
are passed through to the :func:`.fsl_sub` function. are passed through to the :func:`.fsl_sub` function.
...@@ -204,10 +207,11 @@ def run(*args, **kwargs): ...@@ -204,10 +207,11 @@ def run(*args, **kwargs):
submit = kwargs.pop('submit', {}) submit = kwargs.pop('submit', {})
cmdonly = kwargs.pop('cmdonly', False) cmdonly = kwargs.pop('cmdonly', False)
logg = kwargs.pop('log', None) logg = kwargs.pop('log', None)
silent = kwargs.pop('silent', False)
args = prepareArgs(args) args = prepareArgs(args)
if logg is None: if logg is None:
logg = {} logg = {'tee' : not silent}
tee = logg.get('tee', True) tee = logg.get('tee', True)
logStdout = logg.get('stdout', None) logStdout = logg.get('stdout', None)
...@@ -237,7 +241,7 @@ def run(*args, **kwargs): ...@@ -237,7 +241,7 @@ def run(*args, **kwargs):
# but harmless, as we've popped the "submit" arg above. # but harmless, as we've popped the "submit" arg above.
if submit is not None: if submit is not None:
from fsl.wrappers import fsl_sub # pylint: disable=import-outside-toplevel # noqa: E501 from fsl.wrappers import fsl_sub # pylint: disable=import-outside-toplevel # noqa: E501
return fsl_sub(*args, **submit, **kwargs)[0].strip() return fsl_sub(*args, log=logg, **submit, **kwargs)[0].strip()
# Run directly - delegate to _realrun # Run directly - delegate to _realrun
stdout, stderr, exitcode = _realrun( stdout, stderr, exitcode = _realrun(
...@@ -633,10 +637,10 @@ def hold(job_ids, hold_filename=None, timeout=10): ...@@ -633,10 +637,10 @@ def hold(job_ids, hold_filename=None, timeout=10):
submit = { submit = {
'jobhold' : _flatten_job_ids(job_ids), 'jobhold' : _flatten_job_ids(job_ids),
'jobtime' : 1, 'jobtime' : 1,
'name' : '.hold' 'name' : '.hold',
} }
run(f'touch {hold_filename}', submit=submit) run(f'touch {hold_filename}', submit=submit, silent=True)
while not op.exists(hold_filename): while not op.exists(hold_filename):
time.sleep(timeout) time.sleep(timeout)
......
...@@ -193,7 +193,16 @@ def genxwrapper(func, runner, funccmd=False): ...@@ -193,7 +193,16 @@ def genxwrapper(func, runner, funccmd=False):
exitcode = kwargs.pop('exitcode', opts['exitcode']) exitcode = kwargs.pop('exitcode', opts['exitcode'])
submit = kwargs.pop('submit', opts['submit']) submit = kwargs.pop('submit', opts['submit'])
cmdonly = kwargs.pop('cmdonly', opts['cmdonly']) cmdonly = kwargs.pop('cmdonly', opts['cmdonly'])
logg = kwargs.pop('log', opts['log']) silent = kwargs.pop('silent', False)
# If silent=True, we need to explicitly set
# log, as the run function will otherwise
# ignore silent and preferentially use the
# value we pass for log.
if silent:
logg = kwargs.pop('log', {'tee' : False})
else:
logg = kwargs.pop('log', opts['log'])
if funccmd: if funccmd:
cmd = run.func_to_cmd(func, args=args, kwargs=kwargs, cmd = run.func_to_cmd(func, args=args, kwargs=kwargs,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment