add timeout and retry when code execution

This commit is contained in:
lidanyang 2024-01-09 16:14:44 +08:00
parent fe6e46d478
commit fd9f2416ff
2 changed files with 54 additions and 12 deletions

View file

@ -88,3 +88,12 @@ def test_truncate():
assert truncate(output) == output
output = "hello world"
assert truncate(output, 5) == "Truncated to show only the last 5 characters\nworld"
@pytest.mark.asyncio
async def test_run_with_timeout():
pi = ExecutePyCode(timeout=1)
code = "import time; time.sleep(2)"
message, success = await pi.run(code)
assert not success
assert message == "TimeoutError"