| 1 |
Metadata-Version: 2.4 |
| 2 |
Name: con-duct |
| 3 |
Version: 0.21.0 |
| 4 |
Summary: A helper to run a command, capture stdout/stderr and details about running |
| 5 |
Author-email: Austin Macdonald <[email protected]> |
| 6 |
License-Expression: MIT |
| 7 |
Project-URL: source, https://github.com/con/duct/ |
| 8 |
Project-URL: issues, https://github.com/con/duct/issues |
| 9 |
Keywords: command-line,cpu,memory,metrics,output-capture,provenance,time,usage |
| 10 |
Classifier: Development Status :: 3 - Alpha |
| 11 |
Classifier: Programming Language :: Python :: 3 :: Only |
| 12 |
Classifier: Programming Language :: Python :: 3 |
| 13 |
Classifier: Programming Language :: Python :: 3.10 |
| 14 |
Classifier: Programming Language :: Python :: 3.11 |
| 15 |
Classifier: Programming Language :: Python :: 3.12 |
| 16 |
Classifier: Programming Language :: Python :: 3.13 |
| 17 |
Classifier: Programming Language :: Python :: 3.14 |
| 18 |
Classifier: Programming Language :: Python :: Implementation :: CPython |
| 19 |
Classifier: Programming Language :: Python :: Implementation :: PyPy |
| 20 |
Classifier: Environment :: Console |
| 21 |
Classifier: Intended Audience :: Developers |
| 22 |
Classifier: Intended Audience :: Information Technology |
| 23 |
Classifier: Intended Audience :: Science/Research |
| 24 |
Classifier: Intended Audience :: System Administrators |
| 25 |
Classifier: Topic :: System :: Systems Administration |
| 26 |
Classifier: Operating System :: Unix |
| 27 |
Classifier: Operating System :: MacOS |
| 28 |
Requires-Python: >=3.10 |
| 29 |
Description-Content-Type: text/markdown |
| 30 |
License-File: LICENSE |
| 31 |
Provides-Extra: all |
| 32 |
Requires-Dist: matplotlib>=3.5; extra == "all" |
| 33 |
Requires-Dist: PyYAML>=6.0; extra == "all" |
| 34 |
Requires-Dist: pyout>=0.8; extra == "all" |
| 35 |
Requires-Dist: rpds-py<0.28.0; implementation_name == "pypy" and extra == "all" |
| 36 |
Requires-Dist: python-dotenv>=0.19; extra == "all" |
| 37 |
Dynamic: license-file |
| 38 |
|
| 39 |
# con-duct |
| 40 |
|
| 41 |
[](https://codecov.io/gh/con/duct) |
| 42 |
[](https://badge.fury.io/py/con-duct) |
| 43 |
[](https://identifiers.org/RRID:SCR_025436) |
| 44 |
|
| 45 |
A lightweight wrapper that monitors the execution of commands and child processes, collecting stdout/stderr, resource usage data and system information. |
| 46 |
|
| 47 |
The `con-duct` CLI provides multiple subcommands for working with execution data: |
| 48 |
- **`run`**: Execute and monitor commands (also available via the `duct` convenience alias) |
| 49 |
- **`pp`**: Pretty-print JSON logs |
| 50 |
- **`plot`**: Visualize resource usage |
| 51 |
- **`ls`**: List previous executions. |
| 52 |
|
| 53 |
Also see our [Datalad Blog Post](https://blog.datalad.org/posts/intro-duct-tion/) for a hands on example, and |
| 54 |
[duct-gallery](https://github.com/con/duct-gallery) for more samples with plots (contribute yours!). |
| 55 |
|
| 56 |
It is inspired and based on [brainlife's smon](https://github.com/brainlife/abcd-spec/blob/master/hooks/smon) for usage stats collection and our [ReproMan]( |
| 57 |
https://github.com/ReproNim/reproman) for standard outputs capture. |
| 58 |
|
| 59 |
## Installation |
| 60 |
|
| 61 |
Basic installation (includes `con-duct` and `duct` commands): |
| 62 |
|
| 63 |
pip install con-duct |
| 64 |
|
| 65 |
With optional helpers for visualization and analysis (`pp`, `plot`, `ls` commands): |
| 66 |
|
| 67 |
pip install con-duct[all] |
| 68 |
|
| 69 |
## Quickstart |
| 70 |
|
| 71 |
Try it out using either `duct` or `con-duct run`: |
| 72 |
|
| 73 |
duct --sample-interval 0.5 --report-interval 1 test/data/test_script.py --duration 3 --memory-size=1000 |
| 74 |
|
| 75 |
`duct` is most useful when the report-interval is less than the duration of the script. |
| 76 |
|
| 77 |
## Documentation |
| 78 |
|
| 79 |
- [Interpreting duct's resource statistics](docs/resource-statistics.md) — what `pcpu`, `rss`, and the `con-duct plot` chart actually measure, and where the numbers can mislead. |
| 80 |
|
| 81 |
## Reference |
| 82 |
|
| 83 |
### con-duct |
| 84 |
|
| 85 |
<!-- BEGIN EXTRAS HELP --> |
| 86 |
```shell |
| 87 |
>con-duct --help |
| 88 |
|
| 89 |
usage: con-duct <command> [options] |
| 90 |
|
| 91 |
A suite of commands to manage or manipulate con-duct logs. |
| 92 |
|
| 93 |
positional arguments: |
| 94 |
{run,pp,plot,ls} Available subcommands |
| 95 |
run Execute a command with duct monitoring. |
| 96 |
pp Pretty print a JSON log. |
| 97 |
plot Plot resource usage for an execution. |
| 98 |
ls Print execution information for all matching runs. |
| 99 |
|
| 100 |
options: |
| 101 |
-h, --help show this help message and exit |
| 102 |
--version show program's version number and exit |
| 103 |
|
| 104 |
``` |
| 105 |
<!-- END EXTRAS HELP --> |
| 106 |
|
| 107 |
### con-duct run / duct |
| 108 |
|
| 109 |
<!-- BEGIN HELP --> |
| 110 |
```shell |
| 111 |
>duct --help |
| 112 |
|
| 113 |
usage: con-duct run [-h] [-l {NONE,CRITICAL,ERROR,WARNING,INFO,DEBUG}] [-q] |
| 114 |
[--version] [-p OUTPUT_PREFIX] |
| 115 |
[--summary-format SUMMARY_FORMAT] [--colors] [--clobber] |
| 116 |
[--sample-interval SAMPLE_INTERVAL] |
| 117 |
[--report-interval REPORT_INTERVAL] |
| 118 |
[--fail-time FAIL_TIME] [-c {all,none,stdout,stderr}] |
| 119 |
[-o {all,none,stdout,stderr}] |
| 120 |
[-t {all,system-summary,processes-samples}] [-m MESSAGE] |
| 121 |
[--mode {new-session,current-session}] |
| 122 |
command [command_args ...] ... |
| 123 |
|
| 124 |
duct is a lightweight wrapper that collects execution data for an arbitrary |
| 125 |
command. This command can be invoked as either 'duct' or 'con-duct run'. |
| 126 |
|
| 127 |
Execution data includes execution time, system information, and resource usage |
| 128 |
statistics of the command and all its child processes. It is intended to |
| 129 |
simplify the problem of recording the resources necessary to execute a |
| 130 |
command, |
| 131 |
particularly in an HPC environment. |
| 132 |
|
| 133 |
Resource usage is determined by polling (at a sample-interval). |
| 134 |
During execution, duct produces a JSON lines (see https://jsonlines.org) file |
| 135 |
with one data point recorded for each report (at a report-interval). |
| 136 |
|
| 137 |
limitations: |
| 138 |
Duct uses session id to track the command process and its children, so it |
| 139 |
cannot handle the situation where a process creates a new session. |
| 140 |
If a command spawns child processes, duct will collect data on them, but |
| 141 |
duct exits as soon as the primary process exits. |
| 142 |
|
| 143 |
environment variables: |
| 144 |
Many duct options can be configured by environment variables (which are |
| 145 |
overridden by command line options). |
| 146 |
|
| 147 |
DUCT_LOG_LEVEL: see --log-level |
| 148 |
DUCT_OUTPUT_PREFIX: see --output-prefix |
| 149 |
DUCT_SUMMARY_FORMAT: see --summary-format |
| 150 |
DUCT_SAMPLE_INTERVAL: see --sample-interval |
| 151 |
DUCT_REPORT_INTERVAL: see --report-interval |
| 152 |
DUCT_CAPTURE_OUTPUTS: see --capture-outputs |
| 153 |
DUCT_MESSAGE: see --message |
| 154 |
DUCT_CONFIG_PATHS: paths to .env files separated by platform path separator |
| 155 |
(':' on Unix) (see below) |
| 156 |
|
| 157 |
.env files: |
| 158 |
Environment variables can also be set via .env files. By default, duct |
| 159 |
searches the following locations (later files override earlier ones): |
| 160 |
|
| 161 |
- /etc/duct/.env |
| 162 |
- ${XDG_CONFIG_HOME:-~/.config}/duct/.env |
| 163 |
- .duct/.env |
| 164 |
|
| 165 |
Override the search paths by setting DUCT_CONFIG_PATHS with paths separated |
| 166 |
by the platform path separator (':' on Unix) |
| 167 |
(e.g., export DUCT_CONFIG_PATHS="/custom/path.env:~/.myduct.env"). |
| 168 |
|
| 169 |
Example .env file content: |
| 170 |
# Set default log level |
| 171 |
DUCT_LOG_LEVEL=DEBUG |
| 172 |
|
| 173 |
# Configure intervals |
| 174 |
DUCT_SAMPLE_INTERVAL=2.0 |
| 175 |
DUCT_REPORT_INTERVAL=120.0 |
| 176 |
|
| 177 |
# Set default output location |
| 178 |
DUCT_OUTPUT_PREFIX=~/duct-logs/{datetime}-{pid}_ |
| 179 |
|
| 180 |
# Add execution notes (multiline) |
| 181 |
DUCT_MESSAGE="Experiment run for paper revision |
| 182 |
Using updated dataset from 2025-10-30 |
| 183 |
See lab notebook page 42 for details" |
| 184 |
|
| 185 |
Supported .env syntax (via python-dotenv): |
| 186 |
- KEY=value (basic assignment) |
| 187 |
- KEY="value with spaces" (quoted values) |
| 188 |
- KEY='single quotes' (single-quoted values) |
| 189 |
- # comments (hash comments) |
| 190 |
- Empty lines (ignored) |
| 191 |
- Multiline values (use quotes) |
| 192 |
|
| 193 |
Precedence (highest to lowest): |
| 194 |
1. Command line arguments |
| 195 |
2. Explicit environment variables |
| 196 |
3. .env file values (later paths override earlier paths) |
| 197 |
4. Hardcoded defaults |
| 198 |
|
| 199 |
Notes: |
| 200 |
- .env file support requires python-dotenv (pip install con-duct[all]) |
| 201 |
- DUCT_CONFIG_PATHS cannot be set in .env files (must be set before |
| 202 |
loading) |
| 203 |
- Malformed, unreadable, or missing .env files are skipped and logged |
| 204 |
|
| 205 |
positional arguments: |
| 206 |
command [command_args ...] |
| 207 |
The command to execute, along with its arguments. |
| 208 |
command_args Arguments for the command. |
| 209 |
|
| 210 |
options: |
| 211 |
-h, --help show this help message and exit |
| 212 |
-l {NONE,CRITICAL,ERROR,WARNING,INFO,DEBUG}, --log-level {NONE,CRITICAL,ERROR,WARNING,INFO,DEBUG} |
| 213 |
Level of log output to stderr, use NONE to entirely |
| 214 |
disable. (default: INFO) |
| 215 |
-q, --quiet [deprecated, use log level NONE] Disable duct logging |
| 216 |
output (to stderr) (default: False) |
| 217 |
--version show program's version number and exit |
| 218 |
-p OUTPUT_PREFIX, --output-prefix OUTPUT_PREFIX |
| 219 |
File string format to be used as a prefix for the |
| 220 |
files -- the captured stdout and stderr and the |
| 221 |
resource usage logs. The understood variables are |
| 222 |
{datetime} and {pid}. Leading directories will be |
| 223 |
created if they do not exist. You can also provide |
| 224 |
value via DUCT_OUTPUT_PREFIX env variable. (default: |
| 225 |
.duct/logs/{datetime}-{pid}_) |
| 226 |
--summary-format SUMMARY_FORMAT |
| 227 |
Output template to use when printing the summary |
| 228 |
following execution. Accepts custom conversion flags: |
| 229 |
!S: Converts filesizes to human readable units, green |
| 230 |
if measured, red if None. !E: Colors exit code, green |
| 231 |
if falsey, red if truthy, and red if None. !X: Colors |
| 232 |
green if truthy, red if falsey. !N: Colors green if |
| 233 |
not None, red if None (default: Summary: Exit Code: |
| 234 |
{exit_code!E} Command: {command} Log files location: |
| 235 |
{logs_prefix} Wall Clock Time: {wall_clock_time:.3f} |
| 236 |
sec Memory Peak Usage (RSS): {peak_rss!S} Memory |
| 237 |
Average Usage (RSS): {average_rss!S} Virtual Memory |
| 238 |
Peak Usage (VSZ): {peak_vsz!S} Virtual Memory Average |
| 239 |
Usage (VSZ): {average_vsz!S} Memory Peak Percentage: |
| 240 |
{peak_pmem:.2f!N}% Memory Average Percentage: |
| 241 |
{average_pmem:.2f!N}% CPU Peak Usage: |
| 242 |
{peak_pcpu:.2f!N}% Average CPU Usage: |
| 243 |
{average_pcpu:.2f!N}% ) |
| 244 |
--colors Use colors in duct output. (default: False) |
| 245 |
--clobber Replace log files if they already exist. (default: |
| 246 |
False) |
| 247 |
--sample-interval SAMPLE_INTERVAL, --s-i SAMPLE_INTERVAL |
| 248 |
Interval in seconds between status checks of the |
| 249 |
running process. Sample interval must be less than or |
| 250 |
equal to report interval, and it achieves the best |
| 251 |
results when sample is significantly less than the |
| 252 |
runtime of the process. Values below 1.0 behave |
| 253 |
erratically. (default: 1.0) |
| 254 |
--report-interval REPORT_INTERVAL, --r-i REPORT_INTERVAL |
| 255 |
Interval in seconds at which to report aggregated |
| 256 |
data. (default: 60.0) |
| 257 |
--fail-time FAIL_TIME, --f-t FAIL_TIME |
| 258 |
If command fails in less than this specified time |
| 259 |
(seconds), duct would remove logs. Set to 0 if you |
| 260 |
would like to keep logs for a failing command |
| 261 |
regardless of its run time. Set to negative (e.g. -1) |
| 262 |
if you would like to not keep logs for any failing |
| 263 |
command. (default: 3.0) |
| 264 |
-c {all,none,stdout,stderr}, --capture-outputs {all,none,stdout,stderr} |
| 265 |
Record stdout, stderr, all, or none to log files. You |
| 266 |
can also provide value via DUCT_CAPTURE_OUTPUTS env |
| 267 |
variable. (default: all) |
| 268 |
-o {all,none,stdout,stderr}, --outputs {all,none,stdout,stderr} |
| 269 |
Print stdout, stderr, all, or none to stdout/stderr |
| 270 |
respectively. (default: all) |
| 271 |
-t {all,system-summary,processes-samples}, --record-types {all,system-summary,processes-samples} |
| 272 |
Record system-summary, processes-samples, or all |
| 273 |
(default: all) |
| 274 |
-m MESSAGE, --message MESSAGE |
| 275 |
Record a descriptive message about the purpose of this |
| 276 |
execution. You can also provide value via DUCT_MESSAGE |
| 277 |
env variable. (default: ) |
| 278 |
--mode {new-session,current-session} |
| 279 |
Session mode: 'new-session' creates a new session for |
| 280 |
the command (default), 'current-session' tracks the |
| 281 |
current session instead of starting a new one. Useful |
| 282 |
for tracking slurm jobs or other commands that should |
| 283 |
run in the current session. (default: new-session) |
| 284 |
|
| 285 |
``` |
| 286 |
<!-- END HELP --> |
| 287 |
|
| 288 |
### Log Levels |
| 289 |
|
| 290 |
Control duct's verbosity with `--log-level` (or `DUCT_LOG_LEVEL` environment variable): |
| 291 |
|
| 292 |
| Level | Use when... | |
| 293 |
|:-----:|:------------| |
| 294 |
| `NONE` | Running in scripts where you only want the command's output | |
| 295 |
| `ERROR` | You want silence unless something fails | |
| 296 |
| `WARNING` | You want to see potential issues but not routine info | |
| 297 |
| `INFO` | Normal interactive use (default) | |
| 298 |
| `DEBUG` | Troubleshooting duct behavior or unexpected results | |
| 299 |
| `CRITICAL` | You only want the most severe failures reported | |
| 300 |
|
| 301 |
**INFO (default)** - Shows execution status and summary: |
| 302 |
``` |
| 303 |
$ duct echo "hello world" |
| 304 |
2026-01-16T12:01:52 [INFO ] con-duct: duct is executing 'echo hello world'... |
| 305 |
2026-01-16T12:01:52 [INFO ] con-duct: Log files will be written to .duct/logs/2026.01.16T12.01.52-12345_ |
| 306 |
hello world |
| 307 |
2026-01-16T12:01:52 [INFO ] con-duct: Summary: |
| 308 |
Exit Code: 0 |
| 309 |
Command: echo hello world |
| 310 |
... |
| 311 |
``` |
| 312 |
|
| 313 |
**NONE** - Silent operation, only shows command output: |
| 314 |
``` |
| 315 |
$ duct --log-level NONE echo "hello world" |
| 316 |
hello world |
| 317 |
``` |
| 318 |
|
| 319 |
**DEBUG** - Verbose output for troubleshooting: |
| 320 |
``` |
| 321 |
$ duct --log-level DEBUG echo "hello world" |
| 322 |
2026-01-16T12:02:02 [DEBUG ] con-duct: Searching for .env files in: /etc/duct/.env:... |
| 323 |
2026-01-16T12:02:02 [DEBUG ] con-duct: .env file not found (skipping): .duct/.env |
| 324 |
2026-01-16T12:02:02 [INFO ] con-duct: duct is executing 'echo hello world'... |
| 325 |
2026-01-16T12:02:02 [DEBUG ] con-duct: Starting monitoring of the process... |
| 326 |
... |
| 327 |
``` |
| 328 |
|
| 329 |
## FAQs |
| 330 |
|
| 331 |
### git-annex add keeps adding duct logs directly into git |
| 332 |
|
| 333 |
By default, [git-annex](https://git-annex.branchable.com/) treats all dotfiles, and files under directories starting with a `.` as "small" regardless of `annex.largefiles` setting [[ref: an issue describing the logic](https://git-annex.branchable.com/bugs/add__58___inconsistently_treats_files_in_dotdirs_as_dotfiles/?updated#comment-efc1f2aa8f46e88a8be9837a56cfa6f7)]. |
| 334 |
It is necessary to set `annex.dotfiles` variable to `true` to make git-annex treat them as regular files and thus subject to `annex.largefiles` setting [[ref: git-annex config](https://git-annex.branchable.com/git-annex-config/)]. |
| 335 |
Could be done the repository (not just specific clone, but any instance since records in `git-annex` branch) wide using `git annex config --set annex.dotfiles true`. |