From 2408e6e6fefcfbf9961c8f1917c3b111102b0cb2 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Fri, 11 Oct 2019 20:15:52 +0200 Subject: [PATCH] Raise resource limits; raise them again in case of exception The limits were too low to be reasonable with more modern versions of Python. Double exceptions were possible. Make use of soft/hard limits; raise the soft limit in case of exception. That should make it less likely to get a double exception. Per bug report by @LeonaMorro (thanks!) Fixes GitHub issue report #9 (fix #9). --- main.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 6655a62..4a93372 100755 --- a/main.py +++ b/main.py @@ -542,14 +542,16 @@ def main(argv): options &= set(('rsrclimit',)) options.add('prettify') + rsrclimit = False try: if 'rsrclimit' in options: + rsrclimit = True import resource - resource.setrlimit(resource.RLIMIT_CPU, (5, 5)) - resource.setrlimit(resource.RLIMIT_STACK, (393216, 393216)) - resource.setrlimit(resource.RLIMIT_DATA, (4096, 4096)) - resource.setrlimit(resource.RLIMIT_AS, (20001000, 20001000)) + resource.setrlimit(resource.RLIMIT_CPU, (5, 8)) + resource.setrlimit(resource.RLIMIT_STACK, (0x60000, 0x80000)) + resource.setrlimit(resource.RLIMIT_DATA, (9001000, 12001000)) + resource.setrlimit(resource.RLIMIT_AS, (61001000, 81001000)) if 'lso' in options: lslopt.lslcommon.LSO = True @@ -733,6 +735,12 @@ def main(argv): return 0 except Exception as e: + if rsrclimit: + # Raise the soft limits to hopefully prevent double exceptions + resource.setrlimit(resource.RLIMIT_CPU, (8, 8)) + resource.setrlimit(resource.RLIMIT_STACK, (0x80000, 0x80000)) + resource.setrlimit(resource.RLIMIT_DATA, (12001000, 12001000)) + resource.setrlimit(resource.RLIMIT_AS, (81001000, 81001000)) if raise_exception: raise werr(e.__class__.__name__ + ': ' + str(e) + '\n')