mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
refactored timeout (#2044)
This commit is contained in:
parent
752ce8c4ea
commit
cfae6821fa
@ -107,7 +107,7 @@ class DockerExecBox(Sandbox):
|
||||
def __init__(
|
||||
self,
|
||||
container_image: str | None = None,
|
||||
timeout: int = 120,
|
||||
timeout: int = config.sandbox_timeout,
|
||||
sid: str | None = None,
|
||||
):
|
||||
# Initialize docker client. Throws an exception if Docker is not reachable.
|
||||
|
||||
@ -26,7 +26,7 @@ from opendevin.runtime.sandbox import Sandbox
|
||||
|
||||
|
||||
class LocalBox(Sandbox):
|
||||
def __init__(self, timeout: int = 120):
|
||||
def __init__(self, timeout: int = config.sandbox_timeout):
|
||||
os.makedirs(config.workspace_base, exist_ok=True)
|
||||
self.timeout = timeout
|
||||
self.background_commands: dict[int, Process] = {}
|
||||
|
||||
@ -199,7 +199,7 @@ class DockerSSHBox(Sandbox):
|
||||
def __init__(
|
||||
self,
|
||||
container_image: str | None = None,
|
||||
timeout: int = 120,
|
||||
timeout: int = config.sandbox_timeout,
|
||||
sid: str | None = None,
|
||||
):
|
||||
logger.info(
|
||||
@ -219,10 +219,6 @@ class DockerSSHBox(Sandbox):
|
||||
sid + str(uuid.uuid4()) if sid is not None else str(uuid.uuid4())
|
||||
)
|
||||
|
||||
# TODO: this timeout is actually essential - need a better way to set it
|
||||
# if it is too short, the container may still waiting for previous
|
||||
# command to finish (e.g. apt-get update)
|
||||
# if it is too long, the user may have to wait for a unnecessary long time
|
||||
self.timeout = timeout
|
||||
self.container_image = (
|
||||
config.sandbox_container_image
|
||||
@ -432,7 +428,7 @@ class DockerSSHBox(Sandbox):
|
||||
def execute(
|
||||
self, cmd: str, stream: bool = False, timeout: int | None = None
|
||||
) -> tuple[int, str | CancellableStream]:
|
||||
timeout = timeout if timeout is not None else self.timeout
|
||||
timeout = timeout or self.timeout
|
||||
commands = split_bash_commands(cmd)
|
||||
if len(commands) > 1:
|
||||
all_output = ''
|
||||
|
||||
@ -24,7 +24,7 @@ class E2BBox(Sandbox):
|
||||
def __init__(
|
||||
self,
|
||||
template: str = 'open-devin',
|
||||
timeout: int = 120,
|
||||
timeout: int = config.sandbox_timeout,
|
||||
):
|
||||
self.sandbox = E2BSandbox(
|
||||
api_key=config.e2b_api_key,
|
||||
|
||||
@ -36,13 +36,13 @@ from opendevin.storage import FileStore, InMemoryFileStore
|
||||
|
||||
def create_sandbox(sid: str = 'default', sandbox_type: str = 'exec') -> Sandbox:
|
||||
if sandbox_type == 'exec':
|
||||
return DockerExecBox(sid=sid, timeout=config.sandbox_timeout)
|
||||
return DockerExecBox(sid=sid)
|
||||
elif sandbox_type == 'local':
|
||||
return LocalBox(timeout=config.sandbox_timeout)
|
||||
return LocalBox()
|
||||
elif sandbox_type == 'ssh':
|
||||
return DockerSSHBox(sid=sid, timeout=config.sandbox_timeout)
|
||||
return DockerSSHBox(sid=sid)
|
||||
elif sandbox_type == 'e2b':
|
||||
return E2BBox(timeout=config.sandbox_timeout)
|
||||
return E2BBox()
|
||||
else:
|
||||
raise ValueError(f'Invalid sandbox type: {sandbox_type}')
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user