Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/handle-aborted-status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@e2b/code-interpreter-template': patch
---

Handle aborted status
2 changes: 1 addition & 1 deletion template/server/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ async def _process_message(self, data: dict):
traceback="".join(data["content"].get("traceback", [])),
)
)
elif data["content"]["status"] == "abort":
elif data["content"]["status"] in ("abort", "aborted"):
logger.debug(f"Execution {parent_msg_ig} was aborted")
await queue.put(
Error(
Expand Down
20 changes: 19 additions & 1 deletion tests/test_interrupt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import httpx
import pytest

from harness import CodeInterpreter
from harness import CodeInterpreter, Execution


def test_subsequent_execution_works_after_client_timeout(client: CodeInterpreter):
Expand All @@ -18,3 +18,21 @@ def test_subsequent_execution_works_after_client_timeout(client: CodeInterpreter

execution = client.run_code("1 + 1", timeout=10)
assert execution.text == "2"


def test_execution_right_after_client_timeout_does_not_hang(client: CodeInterpreter):
with pytest.raises(httpx.TimeoutException):
client.run_code("import time; time.sleep(300)", timeout=3)

execution = Execution()
started = time.monotonic()
for event in client.stream_code("1 + 1", timeout=10):
execution.add(event)
if time.monotonic() - started > 15:
break

assert execution.completed
if execution.error is not None:
assert execution.error.name == "ExecutionAborted"
else:
assert execution.text == "2"