mirror of
https://github.com/microsoft/autogen.git
synced 2025-11-02 02:40:21 +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```"
|
||||
WORKING_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "extensions")
|
||||
UNKNOWN = "unknown"
|
||||
TIMEOUT_MSG = bytes("Timeout", "utf-8")
|
||||
|
||||
|
||||
def infer_lang(code):
|
||||
@ -180,7 +181,6 @@ def execute_code(
|
||||
filepath = os.path.join(work_dir, filename)
|
||||
file_dir = os.path.dirname(filepath)
|
||||
os.makedirs(file_dir, exist_ok=True)
|
||||
|
||||
if code is not None:
|
||||
with open(filepath, "w") as fout:
|
||||
fout.write(code)
|
||||
@ -202,7 +202,7 @@ def execute_code(
|
||||
except TimeoutError:
|
||||
if original_filename is None:
|
||||
os.remove(filepath)
|
||||
return 1, "Timeout", None
|
||||
return 1, TIMEOUT_MSG, None
|
||||
if original_filename is None:
|
||||
os.remove(filepath)
|
||||
return result.returncode, result.stderr if result.returncode else result.stdout, None
|
||||
@ -260,7 +260,7 @@ def execute_code(
|
||||
container.remove()
|
||||
if original_filename is None:
|
||||
os.remove(filepath)
|
||||
return 1, "Timeout", image
|
||||
return 1, TIMEOUT_MSG, image
|
||||
# try:
|
||||
# container.wait(timeout=timeout)
|
||||
# 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
|
||||
# execute code which takes a long time
|
||||
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)
|
||||
assert exit_code and error == "Timeout" and image is None
|
||||
assert exit_code and error.decode() == "Timeout" and image is None
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user