mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-11-10 20:57:23 +01:00
Prevent commands.process from trying to increase heap size. Closes GH-1353.
This commit is contained in:
parent
c7716de887
commit
06400596e9
@ -72,6 +72,14 @@ class ProcessTimeoutError(Exception):
|
|||||||
"""Gets raised when a process is killed due to timeout."""
|
"""Gets raised when a process is killed due to timeout."""
|
||||||
pass
|
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):
|
def process(f, *args, **kwargs):
|
||||||
"""Runs a function <f> in a subprocess.
|
"""Runs a function <f> in a subprocess.
|
||||||
|
|
||||||
@ -109,7 +117,10 @@ def process(f, *args, **kwargs):
|
|||||||
def newf(f, q, *args, **kwargs):
|
def newf(f, q, *args, **kwargs):
|
||||||
if resource:
|
if resource:
|
||||||
rsrc = resource.RLIMIT_DATA
|
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:
|
try:
|
||||||
r = f(*args, **kwargs)
|
r = f(*args, **kwargs)
|
||||||
q.put(r)
|
q.put(r)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user