fix: 修复 Windows 上 resource 模块导入错误
This commit is contained in:
1 parent
623e550e84
commit
d819502b00
2 files changed
+7
-8
No files matched your search
@@ -10,14 +10,9 @@ from colorama import Fore, Style
|
|||||||
from .config import logger
|
from .config import logger
|
||||||
from .sandbox import (
|
from .sandbox import (
|
||||||
_sandbox_checker, _make_sandbox_worker, _sandbox_work_dir,
|
_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:
|
class CodeExecMixin:
|
||||||
"""代码沙箱执行相关方法"""
|
"""代码沙箱执行相关方法"""
|
||||||
|
|||||||
@@ -4,9 +4,13 @@ import ast as _ast
|
|||||||
import re
|
import re
|
||||||
import textwrap as _textwrap
|
import textwrap as _textwrap
|
||||||
import tempfile as _tempfile
|
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({
|
_BLOCKED_MODULES = frozenset({
|
||||||
'os', 'sys', 'subprocess', 'shutil', 'socket', 'pickle',
|
'os', 'sys', 'subprocess', 'shutil', 'socket', 'pickle',
|
||||||
|
|||||||
Reference in new issue
Block a user