Commit 1bd1ab69 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

Added new fslsub.output function. Bugfix to

parent 14083ed6
......@@ -33,17 +33,20 @@ Example usage, building a short pipeline::
import logging
from six import string_types, BytesIO
import subprocess as sp
import os.path as op
import time
import pickle
import sys
import tempfile
import logging
log = logging.getLogger(__name__)
......@@ -141,7 +144,7 @@ def info(job_id):
result =['qstat', '-j', job_id]).decode('utf-8')
except FileNotFoundError:
log.debug("qstat not found; assumes not not cluster")
log.debug("qstat not found; assuming not on cluster")
return {}
if 'Following jobs do not exist:' in result:
return {}
......@@ -152,6 +155,38 @@ def info(job_id):
return res
def output(job_id, command, cwd='.', name=None):
"""Returns the output of the given job.
:arg job_id: String with job id
:arg command: Command that was run
:arg cwd: Directory from which command was submitted - defaults to
the current directory.
:arg name: Job name if it was specified.
:returns: A tuple containing the standard output and standard error.
if name is None:
name = op.basename(command)
stdout = op.join(cwd, '{}.o{}'.format(name, job_id))
stderr = op.join(cwd, '{}.e{}'.format(name, job_id))
if op.exists(stdout):
with open(stdout, 'rt') as f:
stdout =
stdout = None
if op.exists(stderr):
with open(stderr, 'rt') as f:
stderr =
stderr = None
return stdout, stderr
def wait(job_ids):
"""Wait for one or more jobs to finish
......@@ -212,4 +247,5 @@ def func_to_cmd(func, args, kwargs, tmp_dir=None, clean=False):
with open(filename, 'w') as python_file:
# TODO use current interpreter (e.g. fslpython)?
return "python " + filename + ('; rm ' + filename if clean else '')
......@@ -112,9 +112,9 @@ def run(*args, **kwargs):
``err``), and return code (if ``ret``).
err = kwargs.get('err', False)
ret = kwargs.get('ret', False)
submit = kwargs.get('ret', None)
err = kwargs.get('err', False)
ret = kwargs.get('ret', False)
submit = kwargs.get('submit', None)
args = _prepareArgs(args)
if not bool(submit):
......@@ -185,5 +185,5 @@ def runfsl(*args, **kwargs):
def wait(job_ids):
"""Calls :func:`.fslsub.wait` for the given ``job_ids``. """
"""Proxy for :func:`.fslsub.wait`. """
return fslsub.wait(job_ids)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment