A tool for dispatching tasks using multiprocessing, and viewing/controlling live feedback with a GUI array of progress bars.
Project description
multiprogressbars
multiprogressbars is a Python library for processing tasks via pickled processes using the multiprocessing library. It uses the localhost to communicate progress, which is displayed in real time using a GUI built with PyQt5. The GUI offers some features custom interrupting and throttling tasks for convenience.
Features
Menu appears when right clicking on any bar with the following options:
- Resizeable, moveable, scrollable GUI for displaying the progress bars
- Pinch and scroll zooming by enlarging text
- Autoscrolling enable / disable (so running tasks are always visible)
- Basic speed and remaining time estimation
- Ability to (un)pause any / all tasks.
- Pausing all tasks also is shortcut to the spacebar
- Ability to cancel any given task (signified as 'grey').
- Traceback on any failed tasks without interrupting processing of other tasks (signified as 'red').
- Throttling cpu core usage by dynamically setting the pool size when requested through the menu
- The options range from 1 to your cpu core total and the current tasks are (un)paused appropriately and dispatched when a process becomes available
Structure
Interface
The two interface objects are:
- multiprogressbars.multibar.Multibar
- This object handles creating and dispatching tasks
- multiprogressbars.bar_updater.BarUpdater
- This object handles communicating updates to the progress bar it runs
- It is not necessary for the user to know which bar is run by which process this is done internally
Helpers
The Multibar and BarUpdater objects both have an underlying driver which they inherit from. The Multibar object handles the main GUI and has information about the
- the multiprocessing.Pool
- the tasks
- the progress bars
- the results
The tasks are distributed using QThreads to a multiprogressbars.helpers.process_handler.ProcessHandler object. Each ProcessHandler uses a multiprocessing.Pool to asynchronously run its given task as pickled process. It has a two-way local host multiprocessing.Pipe for the task to communicate its results as they come in, and for the ProcessHandler to signal to interrupt processing if requested.
Installation
Use the package manager pip to install multiprogressbars.
pip install multiprogressbars
For now, PyQt5 must be installed separately with the following command:
pip install pyqt5
Usage
Potential use cases:
For tasks that would benefit from python multiprocessing this is a vast improvement on serial execution. It does not improve on the speed of the multiprocessing library alone.
It is likely to be best used when there are tasks that could be done in parallel that have a long enough iterative execution that individual task progress is worth monitoring. Some examples would be loading and processing a log file, or processing and saving results of a calculation.
Try the examples
First example running randomly generated tasks that take different amounts of time to execute
from multiprogressbars.example import run_example
run_example()
Second example where some tasks will raise an exception
from multiprogressbars.example import run_example_exceptions
run_example_exceptions()
Initialising the main Multibar task handling object
from multiprogressbars.multibar import Multibar
# create the Multibar object - can add tasks and get results through this
mbar = Multibar()
# tasks are created using the following example arguments - they are not run immediately
mbar.add_task(
func=target_func,
func_args=(target_func_arg1, target_func_arg2, ...), # optional
func_kwargs={'target_func_kwarg1_key': target_func_kwarg1_value} # optional
)
# processing begins by calling 'begin_processing()', or 'get()'
# both are blocking until the tasks are finished or the app is quit.
# this quits all processes and returns the results that have already finished
results_dict, failed_tasks_dict = mbar.get()
Adding the BarUpdater object to the target function for callbacks: wrapping
from multiprogressbars.bar_updater import BarUpdater
def target_func(
target_func_arg1,
target_func_arg2,
target_func_kwarg1_key=target_func_kwarg1_value,
pbar: BarUpdater = None):
# wrap an iterator in the BarUpdater object to automatically yield and update the internally designated progress bar
for _ in pbar(iterator, desc=description_str, total=len(iterator)):
# execute code
return results
Adding the BarUpdater object to the target function for callbacks: manually calling
from multiprogressbars.bar_updater import BarUpdater
def target_func(
target_func_arg1,
target_func_arg2,
target_func_kwarg1_key=target_func_kwarg1_value,
pbar: BarUpdater = None):
# wrap an iterator in the BarUpdater object to automatically yield and update the internally designated progress bar
pbar.update_name(description_string)
pbar.update_total(total)
while True:
# execute code
# more complicated user progress calculation
pbar.update_value(new_total_progress)
# break condition
return results
Contributing
Please make any pull requests that would add or fix functionality. This is not intended for major use.
License
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
File details
Details for the file multiprogressbars-0.1.0.tar.gz
.
File metadata
- Download URL: multiprogressbars-0.1.0.tar.gz
- Upload date:
- Size: 27.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e7d21a8c9a3e94f5650294fbe48c2ce9eaa45e602640ab5a9ace428af839d0c |
|
MD5 | b1a8621695c1e5fa9a5e6ba504acbbb3 |
|
BLAKE2b-256 | 505a737291ca260a847816f90ea93846d8ac7edf2beedf76fe36f54f8d46b196 |
File details
Details for the file multiprogressbars-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: multiprogressbars-0.1.0-py3-none-any.whl
- Upload date:
- Size: 35.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e085525ad592b2bfa550ce1a43e30c2221da102a128e7e21550d681a7c90a3fb |
|
MD5 | 1a86e66bea4c90c75ab96e5797ced2bb |
|
BLAKE2b-256 | d2b11c005ffa71c8841e60638ee2b2b72abee6639c041195c08a5b240412781b |