@@ -63,8 +63,8 @@ def tasks():
6363 Returns:
6464 list: List of tasks in default taskmaster
6565 """
66- global _default_task_master
67- return _default_task_master .tasks
66+ global DEFAULT_TASK_MASTER
67+ return DEFAULT_TASK_MASTER .tasks
6868
6969
7070def dict ():
@@ -73,8 +73,8 @@ def dict():
7373 Returns:
7474 dict: Dictionary of tasks in default taskmaster
7575 """
76- global _default_task_master
77- return _default_task_master .dict
76+ global DEFAULT_TASK_MASTER
77+ return DEFAULT_TASK_MASTER .dict
7878
7979
8080def states ():
@@ -83,38 +83,65 @@ def states():
8383 Returns:
8484 dict: Dictionary of task states in default taskmaster
8585 """
86- global _default_task_master
87- return _default_task_master .states
86+ global DEFAULT_TASK_MASTER
87+ return DEFAULT_TASK_MASTER .states
8888
8989
9090def cleanup_tasks ():
91- global _default_task_master
92- return _default_task_master .cleanup ()
91+ """Remove all finished tasks from the task list"""
92+ global DEFAULT_TASK_MASTER
93+ return DEFAULT_TASK_MASTER .cleanup ()
9394
9495
9596def remove_task (task_id : str ):
96- global _default_task_master
97- return _default_task_master .remove (task_id )
97+ """Remove a particular task from the task list
98+
99+ Arguments:
100+ task_id {str} -- ID of the target task
101+ """
102+ global DEFAULT_TASK_MASTER
103+ return DEFAULT_TASK_MASTER .remove (task_id )
98104
99105
100106# Operations on the current task
101107
102108
103109def current_task ():
110+ """Return the Task instance in which the caller is currently running.
111+
112+ If this function is called from outside a Task thread, it will return None.
113+
114+ Returns:
115+ TaskThread -- Currently running Task thread.
116+ """
104117 current_task_thread = threading .current_thread ()
105118 if not isinstance (current_task_thread , TaskThread ):
106119 return None
107120 return current_task_thread
108121
109122
110123def update_task_progress (progress : int ):
124+ """Update the progress of the Task in which the caller is currently running.
125+
126+ If this function is called from outside a Task thread, it will do nothing.
127+
128+ Arguments:
129+ progress {int} -- Current progress, in percent (0-100)
130+ """
111131 if current_task ():
112132 current_task ().update_progress (progress )
113133 else :
114134 logging .info ("Cannot update task progress of __main__ thread. Skipping." )
115135
116136
117137def update_task_data (data : dict ):
138+ """Update the data of the Task in which the caller is currently running.
139+
140+ If this function is called from outside a Task thread, it will do nothing.
141+
142+ Arguments:
143+ data {dict} -- Additional data to merge with the Task data
144+ """
118145 if current_task ():
119146 current_task ().update_data (data )
120147 else :
@@ -132,7 +159,7 @@ def taskify(f):
132159
133160 @wraps (f )
134161 def wrapped (* args , ** kwargs ):
135- task = _default_task_master .new (
162+ task = DEFAULT_TASK_MASTER .new (
136163 f , * args , ** kwargs
137164 ) # Append to parent object's task list
138165 task .start () # Start the function
@@ -142,4 +169,4 @@ def wrapped(*args, **kwargs):
142169
143170
144171# Create our default, protected, module-level task pool
145- _default_task_master = TaskMaster ()
172+ DEFAULT_TASK_MASTER = TaskMaster ()
0 commit comments