feat(sandbox): add convience kwargs to stream output without manual iteration#28
feat(sandbox): add convience kwargs to stream output without manual iteration#28domphan-wandb wants to merge 4 commits intomainfrom
Conversation
|
Thanks for looking into this—this would be nice to have! My one concern is that subprocess.run(..., capture_output=True)
subprocess.run(..., text=True)
requests.get(..., stream=True)Suggestion: Follow the subprocess convention with a import sys
result = sb.exec(["echo", "hi"], stdout=sys.stdout).result() # tee to stdout
result = sb.exec(["echo", "hi"]).result() # capture onlyThis is familiar to Python developers, more flexible (any file-like object works), and removes the need for the env var workaround. Another option could be a fluent result = sb.exec(["echo", "hi"]).tee().result() |
Thanks for the suggestion. I've changed the flag to be Setting |
|
Dropping a 1-off comment before I get to a thorough review in case I don't get to it today: I'm good with the |
|
Note to self: Not being able to redirect stdout/stderr separately seems a little limiting, though probably not a big deal in practice for a convenience flag aimed at interactive debugging. If we want to build a CLI that redirects output properly, we can still do that at that layer. Overall, LGTM |
docs/guides/execution.md
Outdated
| ## Streaming Output | ||
| ## Output Handling | ||
|
|
||
| ### Default: Silent |
There was a problem hiding this comment.
nit: requires explicit handling 🤷
NavarrePratt
left a comment
There was a problem hiding this comment.
Few small comments, but lgtm after cleaning them up.
examples/AGENTS.md
Outdated
| | `cleanup_old_sandboxes.py` | Sync | `def main()` | Age-based cleanup | | ||
|
|
||
| The `exec()` method returns a `Process` object. Call `.result()` to block for the final `ProcessResult`. Iterate over `process.stdout` before calling `.result()` if you need real-time streaming output. | ||
| The `exec()` method returns a `Process` object. Call `.result()` to block for the final `ProcessResult`. By default, output is silent (access via `result.stdout`). For convenience, use `print_output=True` to print output in real-time without manual iteration. |
There was a problem hiding this comment.
Why did we remove the note about how to handle streaming logging? We should keep that in here.
There was a problem hiding this comment.
Same comment about the change in examples/README.md.
docs/guides/execution.md
Outdated
| Both stdout and stderr are printed to stdout. Set `AVIATO_EXEC_PRINT=1` to enable globally. | ||
|
|
||
|
|
There was a problem hiding this comment.
nit: extra blank line
Add
print_outputparameter toexec()for convenient output printingSummary
Adds a
print_outputparameter tosandbox.exec()that controls whether output is printed in real-time. By default,exec()is silent (output available viaresult.stdout). For convenience during debugging, setprint_output=Trueto auto-print output without manual iteration.Motivation
There are use cases where streaming output is needed—watching long-running processes, debugging, or monitoring logs. Previously this required manual iteration:
This PR adds a convenience method to avoid that boilerplate:
This pattern will also be useful for a future CLI where
aviato execcan leverage the same printing behavior.API
print_output: bool = False— new parameter onexec()AVIATO_EXEC_PRINT=1— environment variable to enable printing globallyprint_outputFalse(default)result.stdoutTrueDesign Decisions
Opt-in printing (silent by default)
We chose to make printing opt-in rather than opt-out because:
print_output=Trueclearly signals intentNo prefix on output
Currently, auto-printed output has no prefix (e.g., sandbox ID). This keeps the convenience option simple and unopinionated. If prefixed output is needed (e.g., for multi-sandbox scenarios), users can use manual iteration with their own formatting. We can revisit adding an optional prefix in the future if there's demand.
How to Review
src/aviato/_sandbox.py— theprint_outputparameter flows to_exec_streaming_async()where printing happensAVIATO_EXEC_PRINTcorrectly overridesprint_output=Falseprint_output=True, stderr handling, and env var behaviorpython examples/streaming_exec.pydemonstrates all three output patternsTesting