exec_command: support running .py scripts and -m modules via compile/exec#3362
Open
zdevito wants to merge 4 commits intogh/zdevito/204/basefrom
Open
exec_command: support running .py scripts and -m modules via compile/exec#3362zdevito wants to merge 4 commits intogh/zdevito/204/basefrom
zdevito wants to merge 4 commits intogh/zdevito/204/basefrom
Conversation
…exec Add `BashActor.run_python` endpoint that runs a Python file in-process using `compile`/`exec` rather than spawning a subprocess. Stdout/stderr are redirected via `contextlib.redirect_stdout/redirect_stderr` to either `io.StringIO` buffers (returned in the result dict) or files under `output_dir`. `sys.argv` is patched for the duration. Module execution (`-m module`) is supported by resolving the module to a file path via `importlib.util.find_spec`. `exec_command` detects when `cmd[0]` ends with `.py` or equals `-m` and dispatches to `run_python` instead of the bash path. Also extract `_rank_env` and `_expand_subdir` helpers on `BashActor` to eliminate duplicated rank-env setup across `run`, `run_streaming`, and `run_python`. Differential Revision: [D99526571](https://our.internmc.facebook.com/intern/diff/D99526571/) **NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D99526571/)! [ghstack-poisoned]
zdevito
added a commit
that referenced
this pull request
Apr 4, 2026
…exec Add `BashActor.run_python` endpoint that runs a Python file in-process using `compile`/`exec` rather than spawning a subprocess. Stdout/stderr are redirected via `contextlib.redirect_stdout/redirect_stderr` to either `io.StringIO` buffers (returned in the result dict) or files under `output_dir`. `sys.argv` is patched for the duration. Module execution (`-m module`) is supported by resolving the module to a file path via `importlib.util.find_spec`. `exec_command` detects when `cmd[0]` ends with `.py` or equals `-m` and dispatches to `run_python` instead of the bash path. Also extract `_rank_env` and `_expand_subdir` helpers on `BashActor` to eliminate duplicated rank-env setup across `run`, `run_streaming`, and `run_python`. Differential Revision: [D99526571](https://our.internmc.facebook.com/intern/diff/D99526571/) **NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D99526571/)! ghstack-source-id: 362554090 Pull Request resolved: #3362
…ia compile/exec" Add `BashActor.run_python` endpoint that runs a Python file in-process using `compile`/`exec` rather than spawning a subprocess. Stdout/stderr are redirected via `contextlib.redirect_stdout/redirect_stderr` to either `io.StringIO` buffers (returned in the result dict) or files under `output_dir`. `sys.argv` is patched for the duration. Module execution (`-m module`) is supported by resolving the module to a file path via `importlib.util.find_spec`. `exec_command` detects when `cmd[0]` ends with `.py` or equals `-m` and dispatches to `run_python` instead of the bash path. Also extract `_rank_env` and `_expand_subdir` helpers on `BashActor` to eliminate duplicated rank-env setup across `run`, `run_streaming`, and `run_python`. Differential Revision: [D99526571](https://our.internmc.facebook.com/intern/diff/D99526571/) **NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D99526571/)! [ghstack-poisoned]
zdevito
added a commit
that referenced
this pull request
Apr 4, 2026
…exec Pull Request resolved: #3362 Add `BashActor.run_python` endpoint that runs a Python file in-process using `compile`/`exec` rather than spawning a subprocess. Stdout/stderr are redirected via `contextlib.redirect_stdout/redirect_stderr` to either `io.StringIO` buffers (returned in the result dict) or files under `output_dir`. `sys.argv` is patched for the duration. Module execution (`-m module`) is supported by resolving the module to a file path via `importlib.util.find_spec`. `exec_command` detects when `cmd[0]` ends with `.py` or equals `-m` and dispatches to `run_python` instead of the bash path. Also extract `_rank_env` and `_expand_subdir` helpers on `BashActor` to eliminate duplicated rank-env setup across `run`, `run_streaming`, and `run_python`. ghstack-source-id: 362554680 @exported-using-ghexport Differential Revision: [D99526571](https://our.internmc.facebook.com/intern/diff/D99526571/) **NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D99526571/)!
…ia compile/exec" Add `BashActor.run_python` endpoint that runs a Python file in-process using `compile`/`exec` rather than spawning a subprocess. Stdout/stderr are redirected via `contextlib.redirect_stdout/redirect_stderr` to either `io.StringIO` buffers (returned in the result dict) or files under `output_dir`. `sys.argv` is patched for the duration. Module execution (`-m module`) is supported by resolving the module to a file path via `importlib.util.find_spec`. `exec_command` detects when `cmd[0]` ends with `.py` or equals `-m` and dispatches to `run_python` instead of the bash path. Also extract `_rank_env` and `_expand_subdir` helpers on `BashActor` to eliminate duplicated rank-env setup across `run`, `run_streaming`, and `run_python`. Differential Revision: [D99526571](https://our.internmc.facebook.com/intern/diff/D99526571/) **NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D99526571/)! [ghstack-poisoned]
zdevito
added a commit
that referenced
this pull request
Apr 4, 2026
…exec Pull Request resolved: #3362 Add `BashActor.run_python` endpoint that runs a Python file in-process using `compile`/`exec` rather than spawning a subprocess. Stdout/stderr are redirected via `contextlib.redirect_stdout/redirect_stderr` to either `io.StringIO` buffers (returned in the result dict) or files under `output_dir`. `sys.argv` is patched for the duration. Module execution (`-m module`) is supported by resolving the module to a file path via `importlib.util.find_spec`. `exec_command` detects when `cmd[0]` ends with `.py` or equals `-m` and dispatches to `run_python` instead of the bash path. Also extract `_rank_env` and `_expand_subdir` helpers on `BashActor` to eliminate duplicated rank-env setup across `run`, `run_streaming`, and `run_python`. ghstack-source-id: 362556103 @exported-using-ghexport Differential Revision: [D99526571](https://our.internmc.facebook.com/intern/diff/D99526571/) **NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D99526571/)!
…ia compile/exec" Add `BashActor.run_python` endpoint that runs a Python file in-process using `compile`/`exec` rather than spawning a subprocess. Stdout/stderr are redirected via `contextlib.redirect_stdout/redirect_stderr` to either `io.StringIO` buffers (returned in the result dict) or files under `output_dir`. `sys.argv` is patched for the duration. Module execution (`-m module`) is supported by resolving the module to a file path via `importlib.util.find_spec`. `exec_command` detects when `cmd[0]` ends with `.py` or equals `-m` and dispatches to `run_python` instead of the bash path. Also extract `_rank_env` and `_expand_subdir` helpers on `BashActor` to eliminate duplicated rank-env setup across `run`, `run_streaming`, and `run_python`. Differential Revision: [D99526571](https://our.internmc.facebook.com/intern/diff/D99526571/) **NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D99526571/)! [ghstack-poisoned]
zdevito
added a commit
that referenced
this pull request
Apr 4, 2026
…exec Pull Request resolved: #3362 Add `BashActor.run_python` endpoint that runs a Python file in-process using `compile`/`exec` rather than spawning a subprocess. Stdout/stderr are redirected via `contextlib.redirect_stdout/redirect_stderr` to either `io.StringIO` buffers (returned in the result dict) or files under `output_dir`. `sys.argv` is patched for the duration. Module execution (`-m module`) is supported by resolving the module to a file path via `importlib.util.find_spec`. `exec_command` detects when `cmd[0]` ends with `.py` or equals `-m` and dispatches to `run_python` instead of the bash path. Also extract `_rank_env` and `_expand_subdir` helpers on `BashActor` to eliminate duplicated rank-env setup across `run`, `run_streaming`, and `run_python`. ghstack-source-id: 362590609 @exported-using-ghexport Differential Revision: [D99526571](https://our.internmc.facebook.com/intern/diff/D99526571/) **NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D99526571/)!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
Add
BashActor.run_pythonendpoint that runs a Python file in-processusing
compile/execrather than spawning a subprocess. Stdout/stderrare redirected via
contextlib.redirect_stdout/redirect_stderrto eitherio.StringIObuffers (returned in the result dict) or files underoutput_dir.sys.argvis patched for the duration. Module execution(
-m module) is supported by resolving the module to a file path viaimportlib.util.find_spec.exec_commanddetects whencmd[0]ends with.pyor equals-manddispatches to
run_pythoninstead of the bash path.Also extract
_rank_envand_expand_subdirhelpers onBashActortoeliminate duplicated rank-env setup across
run,run_streaming, andrun_python.Differential Revision: D99526571
NOTE FOR REVIEWERS: This PR has internal Meta-specific changes or comments, please review them on Phabricator!