From f0ace917cfd839bbf16ff03d2383ad63a27317af Mon Sep 17 00:00:00 2001 From: Simon Ye Date: Fri, 17 Feb 2017 14:23:09 -0500 Subject: [PATCH] Set unlimited stacksize for trinity on linux Broad defaults to unlimited stack size, but it may be set lower --- tools/trinity.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tools/trinity.py b/tools/trinity.py index 53a0d2a67..2e4b81dce 100644 --- a/tools/trinity.py +++ b/tools/trinity.py @@ -6,12 +6,15 @@ viral genomes. ''' +import contextlib import logging import os import os.path +import resource import subprocess import tempfile import shutil +import sys import tools TOOL_NAME = "trinity" @@ -21,6 +24,26 @@ log = logging.getLogger(__name__) +@contextlib.contextmanager +def unlimited_stack(): + '''Set the ulimit on stack size to be infinity. + + OS X has a fixed hard stack size limit of 64 MB, so we're not setting it here. + ''' + soft, hard = resource.getrlimit(resource.RLIMIT_STACK) + if sys.platform.startswith('linux'): + new_soft, new_hard = (resource.RLIM_INFINITY, resource.RLIM_INFINITY) + try: + resource.setrlimit(resource.RLIMIT_STACK, (new_soft, new_hard)) + yield + resource.setrlimit(resource.RLIMIT_STACK, (soft, hard)) + except (ValueError, OSError) as e: + log.warning('Error raising stacksize to unlimited: %s', str(e)) + yield + else: + yield + + class TrinityTool(tools.Tool): jvm_mem_default = '4g' @@ -51,7 +74,7 @@ def execute(self, '--output', outdir ] log.debug(' '.join(cmd)) - subprocess.check_call(cmd) + with unlimited_stack(): + subprocess.check_call(cmd) shutil.copyfile(os.path.join(outdir, 'Trinity.fasta'), outFasta) shutil.rmtree(outdir, ignore_errors=True) -