Multiplex is a command-line multiplexer along with a simple Python API to run multiple processes in parallel and stop them all at once, or based on some condition.
Multiplex will gracefully shutdown child processes, and multiplex their output and error streams to stdout and stderr in a way that is easily parsable with regular command line tools.
Multiplex is useful when you need to run multiple programs all at once and combine their output. For instance, you need a webserver, a workqueue and a database to run standalone all together. You could write a shell script, or you could write a one liner using multiplex.
Here's how you'd benchmark Python's embedded HTTP server with a one-liner:
Multiplex is available on PyPI at https://pypi.org/project/multiplex-sh
Quick, from the shell:
Here are some example commands that will help understand the syntax:
Running a simple command:
Running a command after 5s delay:
Running a command after another completes:
Running multiple commands with complex coordination:
Commands follow a structured format: [KEY][+DELAY][|ACTIONS]=COMMAND
- Purpose: Assign a name to a process for reference by other commands
- Format: KEY=command where KEY is alphanumeric (A-Z, a-z, 0-9, _)
- Examples:
- A=python -m http.server
- DB=mongod --port 27017
- API_SERVER=node app.js
Commands can be delayed in two ways:
- Format: +SECONDS where SECONDS can be integer or decimal
- Examples:
- +5=python script.py (wait 5 seconds)
- +1.5=echo "delayed" (wait 1.5 seconds)
- SERVER+10=curl localhost:8000 (named SERVER, wait 10s)
- Format: +PROCESS_NAME wait for named process to complete
- Examples:
- +A=ab -n1000 http://localhost:8000/ (wait for process A)
- +DB=node migrate.js (wait for DB process to complete)
- +SERVER=echo "server is done" (wait for SERVER process)
Actions modify process behavior:
- |end: When this process ends, terminate all other processes
- |silent: Suppress all output (stdout and stderr)
- |noout: Suppress stdout only
- |noerr: Suppress stderr only
Actions can be combined: |silent|end=command
Sequential execution:
Parallel with coordination:
Benchmark pattern:
Development environment:
If your command contains an equals sign, use an empty prefix:
Timeout:
- Format: -t|--timeout SECONDS
- Purpose: Terminate all processes after specified time
- Example: multiplex -t 30 "server=python -m http.server" "test=curl localhost:8000"
The examples/ directory contains practical demonstrations of multiplex features:
Sequential Build (examples/sequential-build.sh)
Demonstrates process-based delays where one command waits for another to complete.
Time-based Delays (examples/time-delays.sh)
Shows different timing patterns with integer and decimal delays.
Process Dependencies (examples/process-delays.sh)
Demonstrates chaining processes where each waits for the previous to complete.
Development Environment (examples/dev-environment.sh)
Simulates starting a full development stack with proper coordination.
Parallel Coordination (examples/parallel-coordination.sh)
Shows how to coordinate multiple services starting in parallel with delays.
CI/CD Pipeline (examples/cicd-pipeline.sh)
Demonstrates a realistic deployment pipeline with sequential steps.
Actions Demo (examples/actions-demo.sh)
Shows silent processes and automatic termination with |end action.
HTTP Benchmark (examples/http-benchmark.sh)
Real HTTP server benchmarking where the test waits for server startup.
Special Cases (examples/special-cases.sh)
Handles commands with equals signs and complex action combinations.
Complete Demo (examples/complete-demo.sh)
Comprehensive example showcasing all features: naming, time/process delays, actions, and coordination.
All examples are executable scripts:
Each example includes descriptive output explaining what's happening during execution.
.png)

