Skip to content

Commit 08a86d0

Browse files
committed
update docs to correct await async devboxes and not use async callbacks (not supported)
1 parent 6c63ef5 commit 08a86d0

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

README-SDK.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ from runloop_api_client import AsyncRunloopSDK
4848

4949
async def main():
5050
sdk = AsyncRunloopSDK()
51-
async with sdk.devbox.create(name="async-devbox") as devbox:
51+
async with await sdk.devbox.create(name="async-devbox") as devbox:
5252
result = await devbox.cmd.exec("pwd")
5353
print(await result.stdout())
5454

55-
async def capture(line: str) -> None:
55+
def capture(line: str) -> None:
5656
print(">>", line)
5757

5858
await devbox.cmd.exec("ls", stdout=capture)
@@ -237,11 +237,15 @@ result = devbox.cmd.exec(
237237
print("exit code:", result.exit_code)
238238
```
239239

240-
Async example:
240+
**Note on Callbacks:** All callbacks (`stdout`, `stderr`, `output`) must be synchronous functions. Even when using `AsyncDevbox`, callbacks cannot be async functions. If you need to perform async operations with the output, use thread-safe queues and process them separately.
241+
242+
Async example (note that the callback itself is still synchronous):
241243

242244
```python
243-
async def capture(line: str) -> None:
244-
await log_queue.put(line)
245+
def capture(line: str) -> None:
246+
# Callbacks must be synchronous
247+
# Use thread-safe data structures if needed
248+
log_queue.put_nowait(line)
245249

246250
await devbox.cmd.exec(
247251
"tail -f /var/log/app.log",
@@ -345,7 +349,7 @@ with sdk.devbox.create(name="temp-devbox") as devbox:
345349
# devbox is automatically shutdown when exiting the context
346350

347351
# Asynchronous
348-
async with sdk.devbox.create(name="temp-devbox") as devbox:
352+
async with await sdk.devbox.create(name="temp-devbox") as devbox:
349353
result = await devbox.cmd.exec("echo 'Hello'")
350354
print(await result.stdout())
351355
# devbox is automatically shutdown when exiting the context
@@ -665,12 +669,12 @@ async def main():
665669
sdk = AsyncRunloopSDK()
666670

667671
# All the same operations, but with await
668-
async with sdk.devbox.create(name="async-devbox") as devbox:
672+
async with await sdk.devbox.create(name="async-devbox") as devbox:
669673
result = await devbox.cmd.exec("pwd")
670674
print(await result.stdout())
671675

672-
# Async streaming
673-
async def capture(line: str) -> None:
676+
# Streaming (note: callbacks must be synchronous)
677+
def capture(line: str) -> None:
674678
print(">>", line)
675679

676680
await devbox.cmd.exec("ls", stdout=capture)

src/runloop_api_client/sdk/_helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Dict, Union, Literal, Callable
66
from pathlib import Path
77

8+
# Callback for streaming output. Must be synchronous even in async contexts.
89
LogCallback = Callable[[str], None]
910

1011
ContentType = Literal["unspecified", "text", "binary", "gzip", "tar", "tgz"]

0 commit comments

Comments
 (0)