Skip to content

Commit c1302e1

Browse files
Merge pull request #141 from codeflash-ai/prevent-memory-crashes
Prevent memory crashes
2 parents 87ea50b + 869bf62 commit c1302e1

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
@@ -6,6 +6,7 @@
66
# System Imports
77
import logging
88
import os
9+
import platform
910
import re
1011
import sys
1112
import time
@@ -36,6 +37,19 @@ class UnexpectedError(Exception):
3637
pass
3738

3839

40+
if platform.system() == "Linux" or platform.system() == "Darwin":
41+
import resource
42+
43+
# Get total system memory
44+
total_memory = os.sysconf("SC_PAGE_SIZE") * os.sysconf(
45+
"SC_PHYS_PAGES"
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)