Registry / devops / executor

executor

JSON →
library23.2pypypi✓ verified 86d ago

The `executor` package is a simple wrapper for Python's `subprocess` module, designed to simplify handling external commands on UNIX systems. It provides an object-oriented interface with proper argument escaping and error checking. Features include support for local commands, remote commands over SSH, execution within chroots, and concurrent command execution through command pools. The library's latest version is 23.2, released in November 2020, with an irregular release cadence.

pip install executor
INSTALL
IMPORT
SIG · EXECUTOR
E
executor
devopspythonv23.2
Install
1.9s avg
Import
166ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v23.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.139s · 19.9MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.9s · import 0.127s · 20MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

execute
from executor import execute
import executor; executor.execute()
The primary function for simple command execution is usually imported directly.
ExternalCommand
from executor import ExternalCommand
Used for more advanced, asynchronous, or pre-configured command execution.
foreach
from executor.ssh.client import foreach
For executing commands concurrently on multiple remote hosts via SSH.

This quickstart demonstrates how to run basic commands, handle their success/failure, provide standard input, and capture standard output using the `execute` function.

from executor import execute import os # Run a simple command and check its success print(f"'true' command success: {execute('true')}") print(f"'false' command success (without check): {execute('false', check=False)}") # Provide input to a command and capture its output output = execute('tr a-z A-Z', input='Hello Python Executor\n', capture=True) print(f"Transformed output: {output.strip()}") # Example of running a command that fails, demonstrating default error handling try: execute('non_existent_command') except Exception as e: print(f"Caught expected error for non-existent command: {e}")
Debug
Known issues
breakingThe `executor` library underwent a significant interface change from version 1.x to 2.x. In 1.x, `execute()` was the sole interface. In 2.x+, the `ExternalCommand` class was introduced for more flexible and asynchronous operations, with `execute()` becoming a wrapper around it. Code written for 1.x using only `execute()` for complex scenarios might need refactoring to leverage `ExternalCommand` in 2.x+.
fix
For complex or asynchronous command execution, migrate from direct `execute()` calls to using `ExternalCommand` instances, calling `start()` and `wait()` as needed. Simple synchronous calls to `execute()` remain compatible.
affects: <2.0.0
gotchaThe `executor` package is explicitly designed for and tested on "UNIX systems." While it might function on other platforms to some extent, full compatibility and all features (like chroot or schroot integration) are not guaranteed on non-UNIX environments (e.g., Windows).
fix
Verify functionality on target non-UNIX platforms or consider alternative libraries if cross-platform compatibility is critical for all features. For basic subprocess execution, it might work, but advanced features are UNIX-specific.
affects: All versions
gotchaBy default, the `execute()` function raises an `ExternalCommandFailed` exception if the external command exits with a non-zero status code. This is a robust error-checking mechanism but can be unexpected if you intend to handle non-zero exit codes as part of normal program flow.
fix
If a non-zero exit code is expected and should not raise an exception, pass `check=False` to the `execute()` function (e.g., `execute('false', check=False)`). The function will then return `False` for failure and `True` for success.
affects: All versions
gotchaThe primary `execute()` function is synchronous and will block the Python interpreter until the external command completes. For long-running commands or to achieve non-blocking execution, you must use the `ExternalCommand` class directly, which provides `start()` for asynchronous initiation and `wait()` to block only when results are needed.
fix
For asynchronous execution, instantiate `ExternalCommand` (e.g., `cmd = ExternalCommand(['long_running_script'])`), call `cmd.start()`, and later `cmd.wait()` to retrieve results, or poll its status.
affects: All versions
breakingIn `executor` version 14.0, the behavior of the `command` property changed. It became valid to set `input` and `shell` options without explicitly providing a `command` argument (which was previously mandatory). Additionally, the `command` property became mutable, allowing it to be changed using normal attribute assignment or reset with `del`.
fix
Review code that relies on implicit `command` requirement or attempts to modify the `command` property directly. While this change generally improves flexibility, older code might rely on the prior, stricter behavior or expect `command` to be immutable after initialization.
affects: <14.0.0
Errors
Common errors & fixes
executor.ExternalCommandFailed: External command failed with exit ...
This error occurs when an external command executed by the `executor` package exits with a non-zero status code, indicating a failure in the command itself. By default, `executor` checks the exit status and raises this exception for any non-zero code.
fix
Catch the `ExternalCommandFailed` exception to handle command failures gracefully. You can access the command's output or error streams from the exception object to diagnose the issue. Alternatively, set `check=False` when calling `execute()` if you don't want non-zero exit codes to raise an exception, though this is generally not recommended for robust error handling.
executor.CommandNotFound: External command not found: ...
This error is raised when the external command specified for execution cannot be found in the system's PATH. This can happen if the command is misspelled, not installed, or not accessible from the environment where `executor` is running.
fix
Verify the correct spelling of the command and ensure it is installed and available in the system's PATH. For remote commands, ensure the command exists on the remote host. You can also specify the full path to the executable to bypass PATH lookups.
ModuleNotFoundError: No module named 'executor'
This error occurs when the Python interpreter cannot find the `executor` package. This typically happens if the package was not installed correctly or if the Python environment where the code is being run does not have `executor` installed.
fix
Install the `executor` package using pip: `pip install executor`. Ensure that you are running your script in the Python environment where the package was installed.
executor.ssh.client.RemoteCommandFailed: Remote command failed with exit ...
Similar to `ExternalCommandFailed`, this specific error indicates that a command executed on a remote host via SSH using `executor.ssh.client` returned a non-zero exit status, signaling a failure in the remote command's execution.
fix
Handle the `RemoteCommandFailed` exception. Inspect the output from the remote command (usually available through the exception object) to understand why it failed. Ensure the command works correctly when executed directly on the remote host via SSH.
Upgrade
Version history
23.2latest on PyPI · released Nov 19, 2020
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
executor — pip install executor · libregistry