Skip to main content

View output of multiple processes, in parallel, in the console, with an interactive TUI

Project description


View output of multiple processes, in parallel, in the console, with an interactive TUI


Parallel Execution Of Commands

mp \
    './ --zone z1' \
    './ --zone z2' \
    './ --zone z3'


You can achive the same effect using Python API like this:

from multiplex import Multiplex

mp = Multiplex()
for zone in ['z1', 'z2', 'z3']:
    mp.add(f"./ --zone {zone}")

Dynamically Add Commands

#!/bin/bash -e
echo Hello There

export REPO=''

mp 'git clone $REPO'
mp 'pyenv virtualenv 3.8.5 multiplex-demo && pyenv local multiplex-demo'
cd multiplex
mp 'poetry install'
mp 'pytest tests'

mp @ Goodbye -b 0

And then running:

mp ./ -b 7


Python Controller

An output similar to the first example can be achieved from a single process using the Python Controller API.

import random
import time
import threading

from multiplex import Multiplex, Controller

CSI = "\033["
RESET = CSI + "0m"
RED = CSI + "31m"
GREEN = CSI + "32m"
BLUE = CSI + "34m"
MAG = CSI + "35m"
CYAN = CSI + "36m"

mp = Multiplex()

controllers = [Controller(f"zone z{i+1}", thread_safe=True) for i in range(3)]

for controller in controllers:

def run(index, c):
        f"Starting long running process in zone {BLUE}z{index}{RESET}, "
        f"that is not really long for demo purposes\n"
    count1 = count2 = 0
    while True:
        count1 += random.randint(0, 1000)
        count2 += random.randint(0, 1000)
        sleep = random.random() * 3
            f"Processed {RED}{count1}{RESET} orders, "
            f"total amount: {GREEN}${count2}{RESET}, "
            f"Time it took to process this batch: {MAG}{sleep:0.2f}s{RESET}, "
            f"Some more random data: {CYAN}{random.randint(500, 600)}{RESET}\n"

for index, controller in enumerate(controllers):
    thread = threading.Thread(target=run, args=(index+1, controller))
    thread.daemon = True


Help Screen

Type ? to toggle the help screen.


Project details

Download files

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

Files for multiplex, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size multiplex-0.2.0-py3-none-any.whl (27.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size multiplex-0.2.0.tar.gz (24.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page