fix: 修复 Windows 上 resource 模块导入错误

This commit is contained in:
xiaoli-cli committed 2026-04-25 22:45:40 +08:00
1 parent 623e550e84
commit d819502b00
2 files changed
+7 -8

No files matched your search

+1 -6
View File
@@ -10,14 +10,9 @@ from colorama import Fore, Style
from .config import logger
from .sandbox import (
_sandbox_checker, _make_sandbox_worker, _sandbox_work_dir,
_HAS_RESOURCE, _SAFE_WHITELIST,
_HAS_RESOURCE, _SAFE_WHITELIST, _resource_mod,
)
try:
import resource as _resource_mod
except ImportError:
_resource_mod = None
class CodeExecMixin:
"""代码沙箱执行相关方法"""
+6 -2
View File
@@ -4,9 +4,13 @@ import ast as _ast
import re
import textwrap as _textwrap
import tempfile as _tempfile
import resource as _resource_mod
_HAS_RESOURCE = hasattr(_resource_mod, 'setrlimit')
try:
import resource as _resource_mod
_HAS_RESOURCE = hasattr(_resource_mod, 'setrlimit')
except ImportError:
_resource_mod = None
_HAS_RESOURCE = False
_BLOCKED_MODULES = frozenset({
'os', 'sys', 'subprocess', 'shutil', 'socket', 'pickle',