mirror of
https://github.com/microsoft/autogen.git
synced 2025-11-09 22:34:29 +00:00
encode timeout msg in bytes (#1078)
* encode timeout msg in bytes * fix msg and test
This commit is contained in:
parent
a30d198530
commit
c5dfb03f0e
@ -13,6 +13,7 @@ from flaml.autogen import oai, DEFAULT_MODEL, FAST_MODEL
|
|||||||
CODE_BLOCK_PATTERN = r"```(\w*)\n(.*?)\n```"
|
CODE_BLOCK_PATTERN = r"```(\w*)\n(.*?)\n```"
|
||||||
WORKING_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "extensions")
|
WORKING_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "extensions")
|
||||||
UNKNOWN = "unknown"
|
UNKNOWN = "unknown"
|
||||||
|
TIMEOUT_MSG = bytes("Timeout", "utf-8")
|
||||||
|
|
||||||
|
|
||||||
def infer_lang(code):
|
def infer_lang(code):
|
||||||
@ -180,7 +181,6 @@ def execute_code(
|
|||||||
filepath = os.path.join(work_dir, filename)
|
filepath = os.path.join(work_dir, filename)
|
||||||
file_dir = os.path.dirname(filepath)
|
file_dir = os.path.dirname(filepath)
|
||||||
os.makedirs(file_dir, exist_ok=True)
|
os.makedirs(file_dir, exist_ok=True)
|
||||||
|
|
||||||
if code is not None:
|
if code is not None:
|
||||||
with open(filepath, "w") as fout:
|
with open(filepath, "w") as fout:
|
||||||
fout.write(code)
|
fout.write(code)
|
||||||
@ -202,7 +202,7 @@ def execute_code(
|
|||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
if original_filename is None:
|
if original_filename is None:
|
||||||
os.remove(filepath)
|
os.remove(filepath)
|
||||||
return 1, "Timeout", None
|
return 1, TIMEOUT_MSG, None
|
||||||
if original_filename is None:
|
if original_filename is None:
|
||||||
os.remove(filepath)
|
os.remove(filepath)
|
||||||
return result.returncode, result.stderr if result.returncode else result.stdout, None
|
return result.returncode, result.stderr if result.returncode else result.stdout, None
|
||||||
@ -260,7 +260,7 @@ def execute_code(
|
|||||||
container.remove()
|
container.remove()
|
||||||
if original_filename is None:
|
if original_filename is None:
|
||||||
os.remove(filepath)
|
os.remove(filepath)
|
||||||
return 1, "Timeout", image
|
return 1, TIMEOUT_MSG, image
|
||||||
# try:
|
# try:
|
||||||
# container.wait(timeout=timeout)
|
# container.wait(timeout=timeout)
|
||||||
# except (ReadTimeout, ConnectionError):
|
# except (ReadTimeout, ConnectionError):
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
__version__ = "2.0.0rc1"
|
__version__ = "2.0.0rc2"
|
||||||
|
|||||||
@ -74,9 +74,9 @@ def test_execute_code():
|
|||||||
assert exit_code, msg
|
assert exit_code, msg
|
||||||
# execute code which takes a long time
|
# execute code which takes a long time
|
||||||
exit_code, error, image = execute_code("import time; time.sleep(2)", timeout=1)
|
exit_code, error, image = execute_code("import time; time.sleep(2)", timeout=1)
|
||||||
assert exit_code and error == "Timeout"
|
assert exit_code and error.decode() == "Timeout"
|
||||||
exit_code, error, image = execute_code("import time; time.sleep(2)", timeout=1, use_docker=False)
|
exit_code, error, image = execute_code("import time; time.sleep(2)", timeout=1, use_docker=False)
|
||||||
assert exit_code and error == "Timeout" and image is None
|
assert exit_code and error.decode() == "Timeout" and image is None
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user