luna.util.progress_tracker module

class ProgressData(input_data, proc_time, output_data=None, exception=None, func=None)[source]

Bases: object

Custom data structure to store data generated during the execution of a single task.

Parameters
  • input_data (any) – The input data of the executed task.

  • proc_time (float) – How long a task took to be executed.

  • output_data (any, optional) – The output data produced by a given task. The data type is the same as the executed function’s return.

  • exception (Exception, optional) – If an exception was raised, then exception stores an Exception object. Otherwise, exception will be set to None.

  • func (function, optional) – The executed function for reference.

class ProgressResult(results=None)[source]

Bases: object

Custom iterable class to store ProgressData objects as they are produced during the execution of a set of tasks.

This class implements append() and __iter__() by default.

Parameters

results (list, optional) – A pre-populated list of ProgressData objects.

Variables

~ProgressResult.results (list) – The list of ProgressData objects.

append(r)[source]

Add a new ProgressData object to results

property errors

Errors from each ProgressData object stored in results. Each tuple contains the input and the exception raised during the execution of a task with that input.

Type

list of tuple

property inputs

Inputs from each ProgressData object stored in results.

Type

list

property outputs

Outputs from each ProgressData object stored in results. Each tuple contains the input and the output produced for that input.

Type

list of tuple

class ProgressTracker(ntasks, queue, task_name=None)[source]

Bases: object

A progress tracker for tasks queued in queue.

Parameters
  • ntasks (int) – The number of tasks to be executed.

  • queue (Queue) – A queue to track the tasks’ progress.

  • task_name (str, optional) – A name to identify the set of tasks.

Variables
  • ~ProgressTracker.ntasks (int) – The number of tasks to be executed.

  • ~ProgressTracker.queue (Queue) – The queue to track the tasks’ progress from.

  • ~ProgressTracker.task_name (str, optional) – The name to identify the set of tasks.

  • ~ProgressTracker.results (ProgressResult) – Store results and any errors found during the tasks’ processing.

  • ~ProgressTracker.nerrors (int) – Number of errors.

property avg_running_time

Average running time.

Type

float

end()[source]

Finish the progress tracker.

property progress

Current number of tasks executed.

Type

int

property running_time

Total running time.

Type

float

start()[source]

Start the progress tracker.