From bb81da9585873a0315d764bef5f2ba6b4b55f147 Mon Sep 17 00:00:00 2001 From: Bernie Pope Date: Wed, 1 Jul 2015 11:28:27 +1000 Subject: [PATCH 1/2] Correct error message when drmaa job exits with non-zero status. Previously it was incorrectly reported as being termnated by a signal --- ruffus/drmaa_wrapper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruffus/drmaa_wrapper.py b/ruffus/drmaa_wrapper.py index aac6a8c..bfab4ce 100644 --- a/ruffus/drmaa_wrapper.py +++ b/ruffus/drmaa_wrapper.py @@ -327,7 +327,7 @@ def stderr_stdout_to_str (stderr, stdout): % (job_info.exitStatus, job_info_str + stderr_stdout_to_str (stderr, stdout))) elif job_info.hasExited: if job_info.exitStatus: - raise error_drmaa_job( "The drmaa command was terminated by signal %i:\n%s" + raise error_drmaa_job( "The drmaa command exited with status %i:\n%s" % (job_info.exitStatus, job_info_str + stderr_stdout_to_str (stderr, stdout))) # # Decorate normal exit with some resource usage information From 3d30bfb646c699b1ddf86beef890439044f6b8f1 Mon Sep 17 00:00:00 2001 From: Bernie Pope Date: Wed, 1 Jul 2015 11:45:20 +1000 Subject: [PATCH 2/2] Allow a drmaa job to retain its stdout and stderr files on completion instead of deleting them --- ruffus/drmaa_wrapper.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/ruffus/drmaa_wrapper.py b/ruffus/drmaa_wrapper.py index bfab4ce..646bc9e 100644 --- a/ruffus/drmaa_wrapper.py +++ b/ruffus/drmaa_wrapper.py @@ -98,7 +98,7 @@ def __init__(self, *errmsg): # read_stdout_stderr_from_files #_________________________________________________________________________________________ -def read_stdout_stderr_from_files( stdout_path, stderr_path, logger = None, cmd_str = "", tries=5): +def read_stdout_stderr_from_files( stdout_path, stderr_path, retain_stdout, retain_stderr, logger = None, cmd_str = "", tries=5): """ Reads the contents of two specified paths and returns the strings @@ -108,7 +108,7 @@ def read_stdout_stderr_from_files( stdout_path, stderr_path, logger = None, cmd_ Logs error if files are missing: No big deal? - Cleans up files afterwards + Cleans up files afterwards, unless requested to keep them Returns tuple of stdout and stderr. @@ -140,13 +140,20 @@ def read_stdout_stderr_from_files( stdout_path, stderr_path, logger = None, cmd_ stderr = [] # - # cleanup ignoring errors + # cleanup ignoring errors, unless requested to keep them # - try: - os.unlink( stdout_path ) - os.unlink( stderr_path ) - except OSError: - pass + + if not retain_stdout: + try: + os.unlink( stdout_path ) + except OSError: + pass + + if not retain_stderr: + try: + os.unlink( stderr_path ) + except OSError: + pass return stdout, stderr @@ -236,7 +243,7 @@ def write_job_script_to_temp_file( cmd_str, job_script_directory, job_name, job_ # run_job_using_drmaa #_________________________________________________________________________________________ -def run_job_using_drmaa (cmd_str, job_name = None, job_other_options = "", job_script_directory = None, job_environment = None, working_directory = None, retain_job_scripts = False, logger = None, drmaa_session = None, verbose = 0): +def run_job_using_drmaa (cmd_str, job_name = None, job_other_options = "", job_script_directory = None, job_environment = None, working_directory = None, retain_job_scripts = False, retain_stdout = False, retain_stderr = False, logger = None, drmaa_session = None, verbose = 0): """ Runs specified command remotely using drmaa, @@ -293,7 +300,7 @@ def run_job_using_drmaa (cmd_str, job_name = None, job_other_options = "", job_s # # Read output # - stdout, stderr = read_stdout_stderr_from_files( stdout_path, stderr_path, logger, cmd_str) + stdout, stderr = read_stdout_stderr_from_files( stdout_path, stderr_path, retain_stdout, retain_stderr, logger, cmd_str) job_info_str = ("The original command was: >> %s <<\n" @@ -517,6 +524,7 @@ def touch_output_files (cmd_str, output_files, logger = None): def run_job(cmd_str, job_name = None, job_other_options = None, job_script_directory = None, job_environment = None, working_directory = None, logger = None, drmaa_session = None, retain_job_scripts = False, + retain_stdout = False, retain_stderr = False, run_locally = False, output_files = None, touch_only = False, verbose = 0, local_echo = False): """ Runs specified command either using drmaa, or locally or only in simulation (touch the output files only) @@ -529,4 +537,4 @@ def run_job(cmd_str, job_name = None, job_other_options = None, job_script_direc if run_locally: return run_job_locally (cmd_str, logger, job_environment, working_directory, local_echo) - return run_job_using_drmaa (cmd_str, job_name, job_other_options, job_script_directory, job_environment, working_directory, retain_job_scripts, logger, drmaa_session, verbose) + return run_job_using_drmaa (cmd_str, job_name, job_other_options, job_script_directory, job_environment, working_directory, retain_job_scripts, retain_stdout, retain_stderr, logger, drmaa_session, verbose)