Skip to content

Commit

Permalink
Merge pull request #585 from broadinstitute/sy-trinity-ulimit
Browse files Browse the repository at this point in the history
Set unlimited stacksize for trinity on linux
  • Loading branch information
tomkinsc authored Feb 17, 2017
2 parents 1033dae + f0ace91 commit 9b0af0d
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions tools/trinity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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'

Expand Down Expand Up @@ -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)

0 comments on commit 9b0af0d

Please sign in to comment.