From 6b7b5032c0950fb111b67aef39ddcef095825740 Mon Sep 17 00:00:00 2001 From: Saurabh Misra Date: Fri, 11 Apr 2025 14:42:24 -0700 Subject: [PATCH 1/3] set resource limit in the pytest plugin --- codeflash/verification/pytest_plugin.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/codeflash/verification/pytest_plugin.py b/codeflash/verification/pytest_plugin.py index 1080ac3e2..e19bf0c81 100644 --- a/codeflash/verification/pytest_plugin.py +++ b/codeflash/verification/pytest_plugin.py @@ -36,6 +36,20 @@ class UnexpectedError(Exception): pass +import platform +if platform.system() == 'Linux' or platform.system() == 'Darwin': + import resource + import psutil + + # Get total system memory + total_memory = psutil.virtual_memory().total + # Set memory limit to 80% of total system memory + memory_limit = int(total_memory * 0.8) + + # Set both soft and hard limits + resource.setrlimit(resource.RLIMIT_AS, (memory_limit, memory_limit)) + + def pytest_addoption(parser: Parser) -> None: """Add command line options.""" pytest_loops = parser.getgroup("loops") From eeac1c0db53eb2d01b49da72e46350e40771ac6b Mon Sep 17 00:00:00 2001 From: Saurabh Misra Date: Fri, 11 Apr 2025 14:51:56 -0700 Subject: [PATCH 2/3] don't require extra package --- codeflash/verification/pytest_plugin.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/codeflash/verification/pytest_plugin.py b/codeflash/verification/pytest_plugin.py index e19bf0c81..9129413cb 100644 --- a/codeflash/verification/pytest_plugin.py +++ b/codeflash/verification/pytest_plugin.py @@ -39,11 +39,10 @@ class UnexpectedError(Exception): import platform if platform.system() == 'Linux' or platform.system() == 'Darwin': import resource - import psutil + import os # Get total system memory - total_memory = psutil.virtual_memory().total - # Set memory limit to 80% of total system memory + total_memory = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') # Set memory limit to 80% of total system memory memory_limit = int(total_memory * 0.8) # Set both soft and hard limits From 869bf62f3ccf9d5a2af0d1bed6e35aec49d75a81 Mon Sep 17 00:00:00 2001 From: Aseem Saxena Date: Fri, 11 Apr 2025 17:22:09 -0700 Subject: [PATCH 3/3] formatting --- codeflash/verification/pytest_plugin.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/codeflash/verification/pytest_plugin.py b/codeflash/verification/pytest_plugin.py index 9129413cb..c47f844de 100644 --- a/codeflash/verification/pytest_plugin.py +++ b/codeflash/verification/pytest_plugin.py @@ -6,6 +6,7 @@ # System Imports import logging import os +import platform import re import sys import time @@ -36,13 +37,13 @@ class UnexpectedError(Exception): pass -import platform -if platform.system() == 'Linux' or platform.system() == 'Darwin': +if platform.system() == "Linux" or platform.system() == "Darwin": import resource - import os # Get total system memory - total_memory = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') # Set memory limit to 80% of total system memory + total_memory = os.sysconf("SC_PAGE_SIZE") * os.sysconf( + "SC_PHYS_PAGES" + ) # Set memory limit to 80% of total system memory memory_limit = int(total_memory * 0.8) # Set both soft and hard limits