Skip to main content

Logging utility for parallel processing applications.

Project description

Parallel Logger

A Python logging utility designed for parallel processing applications. It provides an interactive curses-based terminal UI to monitor and debug logs from multiple threads in real-time.

Features

  • Thread-aware logging: Automatically tracks and organizes logs by thread name
  • Interactive TUI: Navigate between different threads using arrow keys
  • Real-time updates: Logs are displayed as they're generated
  • Easy integration: Simple API with context manager support
  • Thread-safe: Built with thread safety in mind using locks and events

Installation

pip install parallel_logger

Quick Start

Using Context Manager (Recommended)

from concurrent.futures import ThreadPoolExecutor
from time import sleep
from parallel_logger import display_session, pl_print

def task(n):
    pl_print(f"Task {n} starting")
    sleep(n * 3)
    pl_print(f"Task {n} completed")
    return n * n

with display_session():
    with ThreadPoolExecutor(max_workers=3) as executor:
        for i in range(6):
            executor.submit(task, i)

Manual Control

from parallel_logger import start_display, stop_display, pl_print

start_display()
try:
    # Your parallel code here
    pl_print("Hello from thread!")
finally:
    stop_display()

API Reference

Core Functions

pl_print(*args, sep=" ", end="\n")

Records a message for the current thread. Works like Python's built-in print() function but routes output to the parallel logger instead of stdout.

Parameters:

  • *args: Values to print
  • sep: Separator between values (default: " ")
  • end: String appended after the last value (default: "\n")

display_session(refresh_rate=0.1)

Context manager that runs the curses viewer in a helper thread for the duration of the block.

Parameters:

  • refresh_rate: How often to refresh the display in seconds (default: 0.1)

Example:

with display_session(refresh_rate=0.05):
    # Your parallel code here
    pass

start_display(refresh_rate=0.1)

Launches the curses UI on a helper thread and returns the thread object.

Parameters:

  • refresh_rate: How often to refresh the display in seconds (default: 0.1)

Returns: threading.Thread object

stop_display()

Programmatically stops the display loop if it is running.

run_display(refresh_rate=0.1)

Runs the interactive viewer. This is a blocking call that will run until stopped.

Parameters:

  • refresh_rate: How often to refresh the display in seconds (default: 0.1)

is_display_running()

Checks if the UI thread is currently alive.

Returns: bool - True if the display is running, False otherwise

Interactive UI Controls

When the display is running, you can interact with it using:

  • Left Arrow (←): Switch to previous thread
  • Right Arrow (→): Switch to next thread
  • Q: Quit the display

The UI shows:

  • Current thread name and position (e.g., "Thread 2/5: ThreadPoolExecutor-0_1")
  • All logs from the selected thread
  • Navigation instructions in the footer

Requirements

  • Python >= 3.13
  • Standard library only (no external dependencies)

Example

See the included example.py for a complete working demonstration:

python example.py --mode context
python example.py --mode manual

How It Works

The library uses a singleton ParallelLogger instance that:

  1. Collects log messages from each thread separately
  2. Maintains thread order based on first log appearance
  3. Renders logs in a curses-based terminal UI
  4. Allows interactive navigation between thread logs

All logging is thread-safe using threading.Lock() and coordination between threads is managed with threading.Event() objects.

License

See LICENSE file for details.

Author

Luca Mattiazzi

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

parallel_logger-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

parallel_logger-0.1.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file parallel_logger-0.1.0.tar.gz.

File metadata

  • Download URL: parallel_logger-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.8

File hashes

Hashes for parallel_logger-0.1.0.tar.gz
Algorithm Hash digest
SHA256 71048505da78d0d26212bbc5d104c3c6ff516e53068ae1e8b04f7ab35a8f64fe
MD5 5765007e364f87f78fac607bb2c947a1
BLAKE2b-256 b4fbc8570f04d0d901ea1f4206c400fcf9d3d62f0e13b708168964a170317273

See more details on using hashes here.

File details

Details for the file parallel_logger-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for parallel_logger-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 91da6bf8a43fe67dd1f429c76117a8481fb53da7536051627c0a50701813ea1b
MD5 20cbb8d7b46a4b883525635d7a74a814
BLAKE2b-256 88c107861c607482bd1ae6cdd348377d0e3ea481b42cd75fa57ceb77922b6c10

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