mirror of
https://github.com/anthropics/claude-code-sdk-python.git
synced 2025-07-07 22:55:01 +00:00
Added max buffer size in subprocess_cli
This commit is contained in:
parent
591202dd31
commit
6f40c1567b
2 changed files with 10 additions and 3 deletions
|
@ -18,6 +18,8 @@ from ...types import ClaudeCodeOptions
|
|||
from . import Transport
|
||||
|
||||
|
||||
_MAX_BUFFER_SIZE = 1 * 1024 * 1024 # 1MB
|
||||
|
||||
class SubprocessCLITransport(Transport):
|
||||
"""Subprocess transport using Claude Code CLI."""
|
||||
|
||||
|
@ -197,9 +199,13 @@ class SubprocessCLITransport(Transport):
|
|||
json_line = json_line.strip()
|
||||
if not json_line:
|
||||
continue
|
||||
|
||||
|
||||
json_buffer += json_line
|
||||
if(len(json_buffer.encode(self._stdout_stream.encoding)) > _MAX_BUFFER_SIZE):
|
||||
raise OverflowError(f"JSON message buffer exceeded max size: "
|
||||
f"{_MAX_BUFFER_SIZE/(1024*1024)} MB")
|
||||
|
||||
try:
|
||||
json_buffer += json_line
|
||||
data = json.loads(json_buffer)
|
||||
json_buffer = ""
|
||||
try:
|
||||
|
|
|
@ -17,6 +17,7 @@ class MockTextReceiveStream:
|
|||
def __init__(self, lines: list[str]) -> None:
|
||||
self.lines = lines
|
||||
self.index = 0
|
||||
self.encoding = "utf-8"
|
||||
|
||||
def __aiter__(self) -> AsyncIterator[str]:
|
||||
return self
|
||||
|
@ -140,7 +141,7 @@ class TestSubprocessBuffering:
|
|||
|
||||
anyio.run(_test)
|
||||
|
||||
def test_object_over_buffer_limit(self) -> None:
|
||||
def test_objects_over_buffer_limit(self) -> None:
|
||||
"""Test parsing with a json object larger than the buffer limit."""
|
||||
|
||||
async def _test() -> None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue