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 printsep: 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:
- Collects log messages from each thread separately
- Maintains thread order based on first log appearance
- Renders logs in a curses-based terminal UI
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71048505da78d0d26212bbc5d104c3c6ff516e53068ae1e8b04f7ab35a8f64fe
|
|
| MD5 |
5765007e364f87f78fac607bb2c947a1
|
|
| BLAKE2b-256 |
b4fbc8570f04d0d901ea1f4206c400fcf9d3d62f0e13b708168964a170317273
|
File details
Details for the file parallel_logger-0.1.0-py3-none-any.whl.
File metadata
- Download URL: parallel_logger-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91da6bf8a43fe67dd1f429c76117a8481fb53da7536051627c0a50701813ea1b
|
|
| MD5 |
20cbb8d7b46a4b883525635d7a74a814
|
|
| BLAKE2b-256 |
88c107861c607482bd1ae6cdd348377d0e3ea481b42cd75fa57ceb77922b6c10
|