Skip to main content

A lightweight terminal UI for visualizing thread pool activity in real time.

Project description

ci PyPI version

thread-viewer

A lightweight terminal UI for visualizing thread pool activity in real time.

thread-viewer shows:

  • how many tasks are queued, active, and completed
  • which threads are currently active
  • when threads finish and start tasks (via color changes)
  • live activity even under high throughput

It’s built on top of list2term and designed to work naturally with ThreadPoolExecutor.

Features

  • Real-time terminal visualization
  • Colorized activity to make thread reuse visible
  • Minimal API: run() / done()
  • Safe to use in long-running jobs

Installation

pip install thread-viewer

Example

Code
import time
import random
import threading
from concurrent.futures import ThreadPoolExecutor
from thread_viewer.thread_viewer import ThreadViewer

def process_item(item, viewer):
    thread_name = threading.current_thread().name  # e.g. "thread_3"
    viewer.run(thread_name)
    try:
        seconds = random.uniform(.1, 1)
        time.sleep(seconds)
        return seconds
    finally:
        viewer.done(thread_name)

def main():
    items = 120
    num_threads = 24

    with ThreadPoolExecutor(max_workers=num_threads, thread_name_prefix='thread') as executor:
        with ThreadViewer(
            thread_count=num_threads,
            task_count=items,
            thread_prefix='thread_'
        ) as viewer:
            futures = [executor.submit(process_item, item, viewer) for item in range(items)]
            return [future.result() for future in futures]

if __name__ == "__main__":
    main()

example4c

  • Each cell represents a thread
  • Active threads are shown as blocks
  • Every activation changes color so you can see reuse
  • Counts are updated live

API Overview

class ThreadViewer(
    thread_count,               # number of worker threads
    task_count,                 # total number of tasks expected
    thread_prefix='thread_'     # prefix used to extract thread index
)

Creates a terminal viewer. Default works with ThreadPoolExecutor(thread_name_prefix='thread')

Core Methods

Method Description
run(thread_name) Marks a task as started on a thread.
done(thread_name) Marks a task as completed on a thread.

Context manager

Always use ThreadViewer as a context manager:

with ThreadViewer(...) as viewer:

This ensures proper terminal setup and cleanup.

How It Works

  • Uses list2term.Lines for efficient terminal updates
  • Each thread maps to a fixed cell index
  • On every activation - when thread finishes task or starts a new task:
    • the cell is updated
    • a new foreground color is chosen (different from the previous one)
  • This makes activity visible even when threads never truly go idle

No polling. No timers. Just state changes.

When to Use

Good fit if you want:

  • visibility into thread pool behavior
  • confirmation that work is parallelized
  • insight into hot threads or uneven scheduling
  • a lightweight alternative to logging spam

Not intended to replace profilers or tracing tools.

Limitations

  • Terminal-only
  • ANSI colors required
  • Not meant for very narrow terminals
  • Visualization is informational, not a scheduler

Development

Clone the repository and ensure the latest version of Docker is installed on your development server.

Build the Docker image:

docker image build \
-t thread-viewer:latest .

Run the Docker container:

docker container run \
--rm \
-it \
-v $PWD:/code \
thread-viewer:latest \
bash

Execute the dev pipeline:

make dev

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

thread_viewer-1.1.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

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

thread_viewer-1.1.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file thread_viewer-1.1.0.tar.gz.

File metadata

  • Download URL: thread_viewer-1.1.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for thread_viewer-1.1.0.tar.gz
Algorithm Hash digest
SHA256 740b55f0b235de5e116c96fe260cca274ecf9c274e5e74a3c193b7899b23aba2
MD5 fdfa83a08ec6d6be6c6a7ab386c99a43
BLAKE2b-256 0b707471c9de9ad1c01ecaef29d743952964e26d2808f598899d50fc0ab97abd

See more details on using hashes here.

File details

Details for the file thread_viewer-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: thread_viewer-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for thread_viewer-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8f9059559a629a0992e1b6407c4c164aa7e8a4af167f6fb8fa6d96e367a5d9aa
MD5 a3a9cb600084233c0bf03599a9cff552
BLAKE2b-256 01f9dd25c64ab1c309de8c4bb83b18b726f49ac9da5106d93e312ec288f05a3b

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