Skip to main content

Run commands simultaneously

Project description

multiCMD

A simple script that is able to issue multiple commands and execute them at the same time locally.

multiCMD can display realtime-ish outputs in color if running multiple commands at the same time.

Can be used in bash scripts for automation actions.

Also able to be imported and act as a wrapper for subprocess.

For each process, it will initialize a thread if using -m/--max_threads > 1

For each thread, it will use subprocess lib to open a process for the command task

And it will open two sub threads for processing input and output for the task.

They input / output threads will be non-blocking.

Thus using -t/--timeout will work more reliably.

Note: timeout specifies how many seconds multiCMD will kill the command if NO COMMITTED OUTPUT was detected from the program for this long.

An output line is considered committed if steram hanlder encounters a '\n' or '\r' character.

Install via

pip install multiCMD

multiCMD will be available as

mcmd
multiCMD
multicmd
$ mcmd -h
usage: mcmd [-h] [-t timeout] [-m max_threads] [-q] [-V] command [command ...]

Run multiple commands in parallel

positional arguments:
  command               commands to run

optional arguments:
  -h, --help            show this help message and exit
  -t timeout, --timeout timeout
                        timeout for each command
  -m max_threads, --max_threads max_threads
                        maximum number of threads to use
  -q, --quiet           quiet mode
  -V, --version         show program's version number and exit
def run_commands(commands, timeout=0,max_threads=1,quiet=False,dry_run=False,with_stdErr=False,
				 return_code_only=False,return_object=False):
	'''
	Run multiple commands in parallel

	@params:
		commands: A list of commands to run
		timeout: The timeout for each command
		max_threads: The maximum number of threads to use
		quiet: Whether to suppress output
		dry_run: Whether to simulate running the commands
		with_stdErr: Whether to return the standard error output
		return_code_only: Whether to return only the return code
		return_object: Whether to return the Task object

	@returns:
		list: The output of the commands ( list[None] | list[int] | list[list[str]] | list[Task] )
	'''
def run_command(command, timeout=0,max_threads=1,quiet=False,dry_run=False,with_stdErr=False,
				return_code_only=False,return_object=False):
	'''
	Run a command

	@params:
		command: The command to run
		timeout: The timeout for the command
		max_threads: The maximum number of threads to use
		quiet: Whether to suppress output
		dry_run: Whether to simulate running the command
		with_stdErr: Whether to return the standard error output
		return_code_only: Whether to return only the return code
		return_object: Whether to return the Task object

	@returns:
		None | int | list[str] | Task: The output of the command
	'''
def input_with_timeout_and_countdown(timeout, prompt='Please enter your selection'):
	"""
	Read an input from the user with a timeout and a countdown.

	@params:
		timeout: The timeout in seconds
		prompt: The prompt to display to the user

	@returns:
		str: The input from the user or None if no input was received

	"""
def print_progress_bar(iteration, total, prefix='', suffix=''):
	'''
	Call in a loop to create terminal progress bar
	@params:
		iteration   - Required  : current iteration (Int)
		total       - Required  : total iterations (Int)
		prefix      - Optional  : prefix string (Str)
		suffix      - Optional  : suffix string (Str)

	@returns:
		None
	'''
def get_terminal_size():
	'''
	Get the terminal size

	@params:
		None

	@returns:
		(int,int): the number of columns and rows of the terminal
	'''
def int_to_color(n, brightness_threshold=500):
	'''
	Convert an integer to a color

	@params:
		n: The integer
		brightness_threshold: The brightness threshold

	@returns:
		(int,int,int): The RGB color
	'''

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

multicmd-1.13.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

multiCMD-1.13-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file multicmd-1.13.tar.gz.

File metadata

  • Download URL: multicmd-1.13.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for multicmd-1.13.tar.gz
Algorithm Hash digest
SHA256 2e5155535238743a5eecdd7ad60a520eb16456daaaf07eb4f90f5f6bdd0e5c0b
MD5 babaf82238641abf6f73fe9803724dcb
BLAKE2b-256 f00c7c1adccf6d805f9c95b110515df78a1994cc77e5b27d686f3d21473f1408

See more details on using hashes here.

File details

Details for the file multiCMD-1.13-py3-none-any.whl.

File metadata

  • Download URL: multiCMD-1.13-py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for multiCMD-1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 f35c3528421af3f283a00b0426d61fc9f9ffabeea0c512b5ab5951cbb0318e13
MD5 403f316d39d959422743746df6fc87ab
BLAKE2b-256 52f4168c2059a28dd5cc0785aa40369272f01e01802406f1413507274d51af2b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page