Skip to content

Commit 92c1e51

Browse files
committed
fix: handle aborted status
1 parent a4934a5 commit 92c1e51

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@e2b/code-interpreter-template': patch
3+
---
4+
5+
Handle aborted status

‎template/server/messaging.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ async def _process_message(self, data: dict):
569569
traceback="".join(data["content"].get("traceback", [])),
570570
)
571571
)
572-
elif data["content"]["status"] == "abort":
572+
elif data["content"]["status"] in ("abort", "aborted"):
573573
logger.debug(f"Execution {parent_msg_ig} was aborted")
574574
await queue.put(
575575
Error(

‎tests/test_interrupt.py‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import httpx
44
import pytest
55

6-
from harness import CodeInterpreter
6+
from harness import CodeInterpreter, Execution
77

88

99
def test_subsequent_execution_works_after_client_timeout(client: CodeInterpreter):
@@ -18,3 +18,21 @@ def test_subsequent_execution_works_after_client_timeout(client: CodeInterpreter
1818

1919
execution = client.run_code("1 + 1", timeout=10)
2020
assert execution.text == "2"
21+
22+
23+
def test_execution_right_after_client_timeout_does_not_hang(client: CodeInterpreter):
24+
with pytest.raises(httpx.TimeoutException):
25+
client.run_code("import time; time.sleep(300)", timeout=3)
26+
27+
execution = Execution()
28+
started = time.monotonic()
29+
for event in client.stream_code("1 + 1", timeout=10):
30+
execution.add(event)
31+
if time.monotonic() - started > 15:
32+
break
33+
34+
assert execution.completed
35+
if execution.error is not None:
36+
assert execution.error.name == "ExecutionAborted"
37+
else:
38+
assert execution.text == "2"

0 commit comments

Comments
 (0)