Skip to main content

Redirect I/O from processes to different tmux windows

Project description

If you’re prototyping with multiple processes all trying to send debug prints to the same terminal, things can get very confusing.

TmuxProcess is an extension of the multiprocessing Process class which automatically sets up a tmux session with a separate tmux window for each process created. With standard output for each process linked to a separate window, it’s much easier to keep track of what each individual process is doing. (Standard input can also be tied to each separate window, so you can also send different commands to different processes.)

Requirements

tmux, and that’s it!

Installation

pip install tmuxprocess

Usage

If you only care about standard output being redirected:

from tmuxprocess import TmuxProcess
import time

def f(name):
    print("{} running".format(name))
    while True:
        print("{} sleeping".format(name))
        time.sleep(1)

p1 = TmuxProcess(target=f, args=("f1", ))
print("Run")
print("  tmux attach -t {}".format(p1.tmux_sess))
print("to interact with each process.")
p1.start()
p2 = TmuxProcess(target=f, args=("f2", ))
p2.start()

Input and output from the main process will remain on the launching terminal. When the first process is created, a new tmux session will be launched in the background, a new tmux window created in that session, and standard output redirected to that window. When the second process is created, a second tmux window will be created in the same session, and its standard output similarly redirected.

If you also want standard input redirection, initialise with mode='inout':

from tmuxprocess import TmuxProcess

def f(name):
    print("{} running".format(name))
    while True:
        s = input()
        print("{} read:".format(name), s)

p1 = TmuxProcess(target=f, mode='inout', args=("f1", ))
print("Run")
print("  tmux attach -t {}".format(p1.tmux_sess))
print("to interact with each process.")
p1.start()
p2 = TmuxProcess(target=f, mode='inout', args=("f2", ))
p2.start()

However, with this mode, because of the way that standard input redirection is implemented, note that you will have to manually kill the session once done.

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

tmuxprocess-0.2.0.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

tmuxprocess-0.2.0-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file tmuxprocess-0.2.0.tar.gz.

File metadata

  • Download URL: tmuxprocess-0.2.0.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.5

File hashes

Hashes for tmuxprocess-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c14705107c6a796a18c7d374590c569a7e6393c53785caacc35909e0d5c94506
MD5 d85f49890c90da650d190626b5a07a6d
BLAKE2b-256 f618ed6364e2d69494fab7a8271275f3b012e8ad48be407d1c3806659f14286e

See more details on using hashes here.

File details

Details for the file tmuxprocess-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: tmuxprocess-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 3.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.5

File hashes

Hashes for tmuxprocess-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 649a291c4f2282d12da8406e0f3dea9ad8645a653d76c3670ff2f48b6457e560
MD5 8c9456785481d3df69982a137ff253cb
BLAKE2b-256 4a45fd9928527a68a2870f7fb95dd715d54bd9780e65578e9065ddcb36d2dbb6

See more details on using hashes here.

Supported by

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