refactored timeout (#2044)

This commit is contained in:
மனோஜ்குமார் பழனிச்சாமி 2024-05-24 21:49:14 +05:30 committed by GitHub
parent 752ce8c4ea
commit cfae6821fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 9 additions and 13 deletions

View File

@ -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.

View File

@ -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] = {}

View File

@ -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 = ''

View File

@ -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,

View File

@ -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}')