Skip to content

Commit

Permalink
Fix module resource not available in windows (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
rayrayraykk authored Feb 26, 2024
1 parent 7e2ceaa commit ce3c670
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/agentscope/service/execute_code/exec_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import os
import platform
import re
import resource
import shutil
import subprocess
import sys
Expand All @@ -23,6 +22,10 @@
from docker.errors import APIError, ImageNotFound
except ImportError:
docker = None
try:
import resource
except (ModuleNotFoundError, ImportError):
resource = None

from agentscope.utils.common import create_tempdir, timer
from agentscope.service.service_status import ServiceExecStatus
Expand Down Expand Up @@ -332,20 +335,21 @@ def sys_python_guard(maximum_memory_bytes: Optional[int] = None) -> None:
https://github.com/openai/human-eval/blob/master/human_eval/execution.py
"""

if maximum_memory_bytes is not None:
resource.setrlimit(
resource.RLIMIT_AS,
(maximum_memory_bytes, maximum_memory_bytes),
)
resource.setrlimit(
resource.RLIMIT_DATA,
(maximum_memory_bytes, maximum_memory_bytes),
)
if not platform.uname().system == "Darwin":
if resource is not None:
if maximum_memory_bytes is not None:
resource.setrlimit(
resource.RLIMIT_STACK,
resource.RLIMIT_AS,
(maximum_memory_bytes, maximum_memory_bytes),
)
resource.setrlimit(
resource.RLIMIT_DATA,
(maximum_memory_bytes, maximum_memory_bytes),
)
if not platform.uname().system == "Darwin":
resource.setrlimit(
resource.RLIMIT_STACK,
(maximum_memory_bytes, maximum_memory_bytes),
)

# Disable builtins functions
builtins_funcs_to_disable = ["exit", "quit"]
Expand Down

0 comments on commit ce3c670

Please sign in to comment.