Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix module resource not available in win #38

Merged
merged 3 commits into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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