Progress
A collection of functions and classes for getting progress updates.
Function
- pyimpspec.progress.clear_default_handler_output()
Print a blank line with the same length as the previously printed formatted output. The output ends with a carriage return (
\r
) instead of a newline (\n
).
- pyimpspec.progress.register(callback)
Register a callback function that should be invoked when a progress update is emitted.
- Parameters:
callback (Callable) – The callback function should have
*args
and**kwargs
as its arguments.- Returns:
An identifier/handle that can be used to unregister the callback function.
- Return type:
int
- pyimpspec.progress.register_default_handler()
Register the default handler for progress updates. Formats the incoming information and prints it to stdout. The output ends with a carriage return (
\r
) instead of a newline (\n
).
- pyimpspec.progress.unregister(identifier)
Unregister a callback function based on the identifier/handle that was returned when the callback function was registered.
- Parameters:
identifier (int) – The identifier/handle for the callback function that was registered at some point.
- Returns:
True if the callback function was successfully unregistered.
- Return type:
bool
Class
- class pyimpspec.progress.Progress(message, total=1, *args, **kwargs)
Context manager class that can be used to emit information related to progress status. This is used in various parts of the pyimpspec source code to handle the state related to progress and for emitting progress updates as necessary. The
*args
and**kwargs
parameters are passed on to the callback functions whenever a progress update is emitted.- Parameters:
message (str) – The status message to emit.
total (int, optional) – The total number of steps, which is used to emit a percentage.
*args
**kwargs
- get()
Get the current step.
- Return type:
int
- get_total()
Get the current total number of steps.
- Return type:
int
- increment(step=1, force=False)
Increment the progress by a step size ((i + step) / total).
- Parameters:
step (int, optional) – The size of the step to take when called.
force (bool, optional) – Force a progress update to be emitted.
- set(i)
Set the progress in terms of steps (i / total).
- Parameters:
i (int) – The step index.
- set_message(message, i=-1, total=-1, force=True)
Set the status message and optionally also the progress and total number of steps.
- Parameters:
message (str) – The new message.
i (int, optional) – The new step index.
total (int, optional) – The new total number of steps
force (bool, optional) – Force a progress update to be emitted.