fix: set code execution timeout

This commit is contained in:
Yeuoly 2024-03-18 22:12:21 +08:00
parent 5ff2fbed59
commit ac63b5385a
No known key found for this signature in database
GPG Key ID: A66E7E320FB19F61
1 changed files with 3 additions and 1 deletions

View File

@ -13,6 +13,8 @@ from core.helper.code_executor.python_transformer import PythonTemplateTransform
CODE_EXECUTION_ENDPOINT = environ.get('CODE_EXECUTION_ENDPOINT', '')
CODE_EXECUTION_API_KEY = environ.get('CODE_EXECUTION_API_KEY', '')
CODE_EXECUTION_TIMEOUT= (10, 60)
class CodeExecutionException(Exception):
pass
@ -58,7 +60,7 @@ class CodeExecutor:
}
try:
response = post(str(url), json=data, headers=headers)
response = post(str(url), json=data, headers=headers, timeout=CODE_EXECUTION_TIMEOUT)
if response.status_code == 503:
raise CodeExecutionException('Code execution service is unavailable')
elif response.status_code != 200: