mirror of
https://github.com/anthropics/claude-code-sdk-python.git
synced 2025-08-04 12:18:20 +00:00
Merge pull request #5 from Bradley-Butcher/fix/subprocess-buffering-issue
fix multi-line buffering issue
This commit is contained in:
commit
9bda4e8982
2 changed files with 159 additions and 10 deletions
|
@ -188,17 +188,25 @@ class SubprocessCLITransport(Transport):
|
|||
if not line_str:
|
||||
continue
|
||||
|
||||
try:
|
||||
data = json.loads(line_str)
|
||||
# Split on newlines in case multiple JSON objects are buffered together
|
||||
json_lines = line_str.split("\n")
|
||||
|
||||
for json_line in json_lines:
|
||||
json_line = json_line.strip()
|
||||
if not json_line:
|
||||
continue
|
||||
|
||||
try:
|
||||
yield data
|
||||
except GeneratorExit:
|
||||
# Handle generator cleanup gracefully
|
||||
return
|
||||
except json.JSONDecodeError as e:
|
||||
if line_str.startswith("{") or line_str.startswith("["):
|
||||
raise SDKJSONDecodeError(line_str, e) from e
|
||||
continue
|
||||
data = json.loads(json_line)
|
||||
try:
|
||||
yield data
|
||||
except GeneratorExit:
|
||||
# Handle generator cleanup gracefully
|
||||
return
|
||||
except json.JSONDecodeError as e:
|
||||
if json_line.startswith("{") or json_line.startswith("["):
|
||||
raise SDKJSONDecodeError(json_line, e) from e
|
||||
continue
|
||||
|
||||
except anyio.ClosedResourceError:
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue