From 06400596e9d9796f145fe21db1a1791efb16abd0 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sat, 15 Dec 2018 22:15:12 +0100 Subject: [PATCH] Prevent commands.process from trying to increase heap size. Closes GH-1353. --- src/commands.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/commands.py b/src/commands.py index 0582bf7b4..dada7b9d5 100644 --- a/src/commands.py +++ b/src/commands.py @@ -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 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)