diff --git a/lib/assemblers/base.py b/lib/assemblers/base.py index 14fa926..25330b1 100644 --- a/lib/assemblers/base.py +++ b/lib/assemblers/base.py @@ -2,7 +2,7 @@ import datetime from os.path import abspath, basename, exists, getsize, join, splitext -from subprocess import CalledProcessError +from subprocess import CalledProcessError, TimeoutExpired from .. import bio, db_atram, util @@ -72,11 +72,11 @@ def run(self): self.log.info('Assembling shards with {}: iteration {}'.format( self.args['assembler'], self.state['iteration'])) self.assemble() - except TimeoutError: + except (TimeoutExpired, TimeoutError): msg = 'Time ran out for the assembler after {} (HH:MM:SS)'.format( datetime.timedelta(seconds=self.args['timeout'])) self.log.error(msg) - raise TimeoutError(msg) + raise TimeoutExpired(msg, timeout=self.args['timeout']) except CalledProcessError as cpe: msg = 'The assembler failed with error: ' + str(cpe) self.log.error(msg) diff --git a/lib/core_atram.py b/lib/core_atram.py index 463f1cc..dec168e 100644 --- a/lib/core_atram.py +++ b/lib/core_atram.py @@ -4,6 +4,7 @@ import re from multiprocessing import Pool from os.path import basename, join, split, splitext +from subprocess import TimeoutExpired from Bio import SeqIO @@ -34,7 +35,7 @@ def assemble(args): try: assembly_loop(args, log, assembler, blast_db, query) - except (TimeoutError, RuntimeError): + except (TimeoutExpired, TimeoutError, RuntimeError): pass except Exception as err: # pylint: disable=broad-except log.error('Exception: {}'.format(err)) diff --git a/lib/db.py b/lib/db.py index cdcedfb..e8ff0ce 100644 --- a/lib/db.py +++ b/lib/db.py @@ -5,7 +5,7 @@ import sys from os.path import basename, exists, join -ATRAM_VERSION = 'v2.3.4' +ATRAM_VERSION = 'v2.3.5' # DB_VERSION != ATRAM_VERSION # We don't force DB changes until required. diff --git a/lib/log.py b/lib/log.py index f903234..9aac8e8 100644 --- a/lib/log.py +++ b/lib/log.py @@ -49,6 +49,8 @@ def subcommand(self, cmd, temp_dir, timeout=None): """ self.debug(cmd) + error = None + with tempfile.NamedTemporaryFile(mode='w', dir=temp_dir) as log_output: try: subprocess.check_call( @@ -59,12 +61,15 @@ def subcommand(self, cmd, temp_dir, timeout=None): stderr=log_output) except Exception as err: # pylint: disable=broad-except self.error('Exception: {}'.format(err)) + error = err finally: with open(log_output.name) as log_input: for line in log_input: line = line.strip() if line: self.debug(line) + if error: + raise error def _output(self, msg, level): timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')