Prevent commands.process from trying to increase heap size. Closes GH-1353.

This commit is contained in:
Valentin Lorentz 2018-12-15 22:15:12 +01:00
parent c7716de887
commit 06400596e9
1 changed files with 12 additions and 1 deletions

View File

@ -72,6 +72,14 @@ class ProcessTimeoutError(Exception):
"""Gets raised when a process is killed due to timeout."""
pass
def _rlimit_min(a, b):
if a == resource.RLIM_INFINITY:
return b
elif b == resource.RLIM_INFINITY:
return a
else:
return min(soft, heap_size)
def process(f, *args, **kwargs):
"""Runs a function <f> in a subprocess.
@ -109,7 +117,10 @@ def process(f, *args, **kwargs):
def newf(f, q, *args, **kwargs):
if resource:
rsrc = resource.RLIMIT_DATA
resource.setrlimit(rsrc, (heap_size, heap_size))
(soft, hard) = resource.getrlimit(rsrc)
soft = _rlimit_min(soft, heap_size)
hard = _rlimit_min(hard, heap_size)
resource.setrlimit(rsrc, (soft, hard))
try:
r = f(*args, **kwargs)
q.put(r)