Skip to main content

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

For a quick test to see everything is working as it should, try:

python multiprogressbars/example.py

or

python multiprogressbars/example.py --with_exceptions

For testing with control over the parameters for the number of tasks, task names, iteration speeds and totals, import the examples into a python script. 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

GNU GPL

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

multiprogressbars-0.1.1.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

multiprogressbars-0.1.1-py3-none-any.whl (36.0 kB view details)

Uploaded Python 3

File details

Details for the file multiprogressbars-0.1.1.tar.gz.

File metadata

  • Download URL: multiprogressbars-0.1.1.tar.gz
  • Upload date:
  • Size: 27.8 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

Hashes for multiprogressbars-0.1.1.tar.gz
Algorithm Hash digest
SHA256 959f45cc02d356ca94f262ce4b015b116bf9a4707dc9f77364169cadee9b8f14
MD5 8e479fc90c49c7022282de84bf1ef2a0
BLAKE2b-256 652512e426fde8d99b9b76eb18690738689e1ea733499fc18588c5cb7a3d348c

See more details on using hashes here.

File details

Details for the file multiprogressbars-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: multiprogressbars-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 36.0 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

Hashes for multiprogressbars-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 73ea4464f2785e27a788334a13b3d77449e72a610f810a6b7c71e0c07bdac6b4
MD5 f51a0ae06b6725a333e2ca009448f424
BLAKE2b-256 6a60f4db1e4230d37f8e590f5fe14c39e9dc55643923cd1dc67fce3fd5753572

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