Skip to content

Commit 5d64021

Browse files
committed
Merge remote-tracking branch 'origin/prevent-memory-crashes' into cf-600
2 parents de0fa75 + b6bd030 commit 5d64021

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

codeflash/verification/pytest_plugin.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ class UnexpectedError(Exception):
3636
pass
3737

3838

39+
import platform
40+
if platform.system() == 'Linux' or platform.system() == 'Darwin':
41+
import resource
42+
import psutil
43+
44+
# Get total system memory
45+
total_memory = psutil.virtual_memory().total
46+
# Set memory limit to 80% of total system memory
47+
memory_limit = int(total_memory * 0.8)
48+
49+
# Set both soft and hard limits
50+
resource.setrlimit(resource.RLIMIT_AS, (memory_limit, memory_limit))
51+
52+
3953
def pytest_addoption(parser: Parser) -> None:
4054
"""Add command line options."""
4155
pytest_loops = parser.getgroup("loops")

0 commit comments

Comments
 (0)