You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README-SDK.md
+13-9Lines changed: 13 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,11 +48,11 @@ from runloop_api_client import AsyncRunloopSDK
48
48
49
49
asyncdefmain():
50
50
sdk = AsyncRunloopSDK()
51
-
asyncwith sdk.devbox.create(name="async-devbox") as devbox:
51
+
asyncwithawaitsdk.devbox.create(name="async-devbox") as devbox:
52
52
result =await devbox.cmd.exec("pwd")
53
53
print(await result.stdout())
54
54
55
-
asyncdefcapture(line: str) -> None:
55
+
defcapture(line: str) -> None:
56
56
print(">>", line)
57
57
58
58
await devbox.cmd.exec("ls", stdout=capture)
@@ -237,11 +237,15 @@ result = devbox.cmd.exec(
237
237
print("exit code:", result.exit_code)
238
238
```
239
239
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):
241
243
242
244
```python
243
-
asyncdefcapture(line: str) -> None:
244
-
await log_queue.put(line)
245
+
defcapture(line: str) -> None:
246
+
# Callbacks must be synchronous
247
+
# Use thread-safe data structures if needed
248
+
log_queue.put_nowait(line)
245
249
246
250
await devbox.cmd.exec(
247
251
"tail -f /var/log/app.log",
@@ -345,7 +349,7 @@ with sdk.devbox.create(name="temp-devbox") as devbox:
345
349
# devbox is automatically shutdown when exiting the context
346
350
347
351
# Asynchronous
348
-
asyncwith sdk.devbox.create(name="temp-devbox") as devbox:
352
+
asyncwithawaitsdk.devbox.create(name="temp-devbox") as devbox:
349
353
result =await devbox.cmd.exec("echo 'Hello'")
350
354
print(await result.stdout())
351
355
# devbox is automatically shutdown when exiting the context
@@ -665,12 +669,12 @@ async def main():
665
669
sdk = AsyncRunloopSDK()
666
670
667
671
# All the same operations, but with await
668
-
asyncwith sdk.devbox.create(name="async-devbox") as devbox:
672
+
asyncwithawaitsdk.devbox.create(name="async-devbox") as devbox:
0 commit comments