API¶
The progrock.MultiProgress
class is used in conjunction with the
methods exposed at the module level such as progrock.increment()
to
create a full-screen experience allowing the user to track the progress of
individual processes as they perform their work.
This module is meant as a complement to multiprocessing.Process
and
provide an easy to use, yet opinionated view of child process progress bars.
-
class
progrock.
MultiProgress
(title=None, steps=None, value=0)¶ The MultiProgress class is responsible for rendering the progress screen using curses. In addition, it can wrap the creation of processes for you to automatically pass in the
multiprocessing.Queue
object that is used to issue commands for updating the UI.If you do not pass in a
title
for the application, the Python file that is being run will be used as a title for the screen.If you pass in
steps
, a progress bar will be centered in the footer to display the overall progress of an application. The bar can be incremented from the parent process usingMultiProgress.increment_app()
or if you’re incrementing from a child process, you can callprogrock.increment_app()
passing inipc_queue
.Parameters: -
add_process
(process, status='Initializing', steps=100, value=0)¶ Add a process to the MultiProgress display. The process must already have been started proior to invoking this method.
Parameters: - multiprocessing.Process – The process to add
- status (str) – The status text for the process box
- steps (int|float) – The number of steps for the progress bar
- value (int|float) – Current progress value for the process
-
increment_app
(value=1)¶ If using the application progress bar, increment the progress of the bar.
Parameters: value (int) – The value to increment by. Default: 1
-
initialize
()¶ Initialize the
MultiProgress
screen. Should only be invoked if not using theMultiProgress
instance as a context manager. If the instanceMultiProgress
instance is used as a context manager, this is done automatically.
-
new_process
(target, name=None, args=None, kwargs=None, status='Initializing', steps=100, value=0)¶ Create and start new
multiprocessing.Process
instance, automatically appending the update queue to the positional arguments passed into the target when the process is started. Once the process is created, it is added to the stack of processes inMultiProgress
, bypassing the need to invokeMutiProgress.add_process()
.Parameters: - target (method) – The method to invoke when the process starts
- name (str) – Process name
- args (tuple) – Positional arguments to pass into the process
- kwargs (dict) – Keyword arguments to pass into the process
- status (str) – The status text for the process box
- steps (int|float) – The number of steps for the progress bar
- value (int|float) – Current progress value for the process
Returns: multiprocessing.Process
-
shutdown
()¶ Shutdown
MultiProgress
screen. Must be called if theMultiProgress
instance is not being used as a context manager. If the instanceMultiProgress
instance is used as a context manager, this is done automatically.
-
-
progrock.
increment
(ipc_queue, value=1)¶ Increment the progress value for the current process, passing in the queue exposed by
MultiProgress.ipc_queue
and automatically passed into the target function when creating the process withMultiProgress.new_process
.Parameters: - ipc_queue (multiprocessing.Queue) – The IPC command queue
- value (int) – The value to increment by. Default:
1
-
progrock.
increment_app
(ipc_queue, value=1)¶ Increment the progress value for the application, passing in the queue exposed by
MultiProgress.ipc_queue
.Parameters: - ipc_queue (multiprocessing.Queue) – The IPC command queue
- value (int) – The value to increment by. Default:
1
-
progrock.
reset_start_time
(ipc_queue)¶ Restart the start time of a process, passing in the queue exposed by
MultiProgress.ipc_queue
and automatically passed into the target function when creating the process withMultiProgress.new_process
.Parameters: ipc_queue (multiprocessing.Queue) – The IPC command queue
-
progrock.
reset_value
(ipc_queue)¶ Reset the progress value for the current process, passing in the queue exposed by
MultiProgress.ipc_queue
and automatically passed into the target function when creating the process withMultiProgress.new_process
.Parameters: ipc_queue (multiprocessing.Queue) – The IPC command queue
-
progrock.
set_app_step_count
(ipc_queue, steps)¶ Set the number of steps for the application, passing in the queue exposed by
MultiProgress.ipc_queue
.Parameters: - ipc_queue (multiprocessing.Queue) – The IPC command queue
- steps (int) – The number of steps for the application.
-
progrock.
set_status
(ipc_queue, status)¶ Set the status of current process, passing in the queue exposed by
MultiProgress.ipc_queue
and automatically passed into the target function when creating the process withMultiProgress.new_process
.Parameters: - ipc_queue (multiprocessing.Queue) – The IPC command queue
- status (str) – The status text for the current process
-
progrock.
set_step_count
(ipc_queue, steps)¶ Set the number of steps for current process, passing in the queue exposed by
MultiProgress.ipc_queue
and automatically passed into the target function when creating the process withMultiProgress.new_process
.Parameters: - ipc_queue (multiprocessing.Queue) – The IPC command queue
- steps (int) – The number of steps for the current process
-
progrock.
set_value
(ipc_queue, value)¶ Set the progress value for the current process, passing in the queue exposed by
MultiProgress.ipc_queue
and automatically passed into the target function when creating the process withMultiProgress.new_process
.Parameters: - ipc_queue (multiprocessing.Queue) – The IPC command queue
- value (int) – The value to set for the process