diff --git a/xmodule/capa/safe_exec/safe_exec.py b/xmodule/capa/safe_exec/safe_exec.py index e9181f85a0..bfc98bb221 100644 --- a/xmodule/capa/safe_exec/safe_exec.py +++ b/xmodule/capa/safe_exec/safe_exec.py @@ -21,7 +21,17 @@ CODE_PROLOG = """\ from __future__ import absolute_import, division import os -os.environ["OPENBLAS_NUM_THREADS"] = "1" # See TNL-6456 + +# openblas is a math library used by numpy. It will try to allocate multiple +# threads by default, but this may exceed resource limits and cause a segfault. +# Limiting to 1 thread will prevent this in all configurations. +os.environ["OPENBLAS_NUM_THREADS"] = "1" + +# Any code that uses the tempfile module to create temporary files should use +# the ./tmp directory that codejail creates in each sandbox, rather than trying +# to use a global temp dir (which should be blocked by AppArmor anyhow). +# This is needed for matplotlib among other things. +os.environ["TMPDIR"] = os.getcwd() + "/tmp" import random2 as random_module import sys