API Reference
This page is automatically generated from the source code docstrings.
CircularDependencyError
Bases: Exception
Raised when circular dependencies are detected among tasks.
Source code in src/processes/process.py
20 21 22 23 | |
DependencyNotFoundError
Bases: Exception
Raised when a task depends on a non-existent task.
Source code in src/processes/process.py
8 9 10 11 | |
Process
Manages and executes a collection of interdependent tasks.
A Process orchestrates the execution of multiple tasks, handling dependency resolution, task ordering. Task execution can be performed in parallel or sequentially. It provides logging management and error propagation for dependent tasks. If a task fails, all tasks depending on it are marked as failed without execution, but non-dependent tasks continue to run.
Attributes
tasks : list[Task] List of tasks to be executed, automatically sorted by dependencies. runner : ProcessRunner The runner responsible for executing the tasks.
Raises
TypeError If tasks is not a list or contains non-Task elements. ValueError If duplicate task names are found. DependencyNotFoundError If a task depends on a non-existent task. CircularDependencyError If circular dependencies are detected among tasks.
Source code in src/processes/process.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
__enter__()
Called when entering the 'with' block.
Source code in src/processes/process.py
88 89 90 | |
__exit__(exc_type, exc_value, traceback)
Called when exiting the 'with' block, even if an error occurred.
Source code in src/processes/process.py
92 93 94 95 96 97 98 99 100 | |
close_loggers()
Close and clean up all logger handlers for all tasks.
Should be called when the process is done to ensure proper resource cleanup.
Source code in src/processes/process.py
262 263 264 265 266 267 268 269 270 | |
get_dependant_tasks(task_name)
Retrieve all tasks that directly or indirectly depend on a given task.
Parameters
task_name : str The name of the task to find dependants for.
Returns
list[Task] List of all tasks that depend on the specified task, including transitive dependencies (tasks that depend on tasks that depend on the specified task).
Source code in src/processes/process.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
get_task(task_name)
Retrieve a task by name.
Parameters
task_name : str The name of the task to retrieve.
Returns
Task The task with the specified name.
Raises
TaskNotFoundError If no task with the given name exists.
Source code in src/processes/process.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
run(parallel=None, max_workers=4)
Execute all tasks in the process.
Runs tasks sequentially or in parallel while respecting dependencies. Dependencies are always resolved before dependent tasks are executed.
Parameters
parallel : bool, optional Whether to run tasks in parallel while respecting dependencies. If None, automatically set to True for processes with 10 or more tasks, False otherwise. Defaults to None. max_workers : int, optional Maximum number of worker threads for parallel execution. Defaults to 4. Only used when parallel=True. If set to 1, falls back to sequential execution.
Returns
ProcessResult Contains passed_tasks_results (dict mapping task names to TaskResult) and failed_tasks (set of task names that failed).
Source code in src/processes/process.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
ProcessResult
Container for the results of a process execution.
Holds the outcomes of all tasks executed in a process, separating successful and failed tasks with their respective results.
Attributes
passed_tasks_results : dict[str, TaskResult] Mapping of task names to TaskResult objects for all tasks that executed successfully. failed_tasks : set[str] Set of task names for all tasks that failed during execution.
Source code in src/processes/process.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
ProcessRunner
Executes tasks in a Process, handling both sequential and parallel execution.
Manages task execution state, tracks passed and failed tasks, and coordinates dependencies during execution.
Attributes
process : Process Reference to the parent Process being executed. passed_results : dict[str, TaskResult] Results from successfully executed tasks. failed_tasks : set[str] Names of tasks that failed during execution. submitted_tasks : set[str] Names of tasks that have been submitted for execution.
Source code in src/processes/process.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |
run(parallel, max_workers)
Execute all tasks in the process using the specified execution mode.
Parameters
parallel : bool If True, execute tasks in parallel; otherwise execute sequentially. max_workers : int Maximum number of worker threads for parallel execution.
Returns
ProcessResult The combined results of all task executions.
Source code in src/processes/process.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
TaskNotFoundError
Bases: Exception
Raised when attempting to retrieve a task that does not exist in the process.
Source code in src/processes/process.py
14 15 16 17 | |
Task
A Task represents a unit of work to be executed within a Process.
A Task encapsulates a callable function with its arguments, dependencies on other tasks, and logging configuration. Tasks can be executed, by the Process class, sequentially or in parallel, with automatic dependency resolution and result passing between dependent tasks.
Attributes
name : str Unique name for the task (cannot contain spaces). log_path : str File path where task logs will be written. func : Callable The function to execute when the task runs. args : tuple Positional arguments to pass to the function. Defaults to empty tuple. kwargs : dict Keyword arguments to pass to the function. Defaults to empty dict. dependencies : list[TaskDependency] List of tasks this task depends on. Defaults to empty list. html_mail_handler : HTMLSMTPHandler, optional Handler for sending error logs via email in HTML format. Defaults to None. logger : logging.Logger Logger instance for this task, automatically configured.
Source code in src/processes/task.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
get_dependencies_names()
Get the names of all tasks this task depends on.
Returns
set[str] Set of dependency task names.
Source code in src/processes/task.py
235 236 237 238 239 240 241 242 243 244 | |
run(executing_process=None)
Execute the task's function with its arguments and dependencies.
This method runs the task's function, automatically injecting results from dependent tasks as specified in the dependency configuration. Logs the task execution and captures any exceptions.
Parameters
executing_process : Process, optional The parent Process executing this task. Used to retrieve results from dependent tasks. Defaults to None.
Returns
TaskResult Object containing: - worked (bool): True if execution succeeded, False otherwise. - result: The return value of the function if successful, None if failed. - exception (Exception | None): The exception raised if execution failed, None if successful.
Source code in src/processes/task.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
TaskDependency
Represents a dependency relationship between tasks.
Defines how a task depends on another task, including how the result of the dependency should be passed to the dependent task (as additional positional arguments, keyword arguments, or both).
Attributes
task_name : str The name of the task this dependency refers to. use_result_as_additional_args : bool If True, the result of the dependency task will be passed as an additional positional argument as the last argument. Defaults to False. use_result_as_additional_kwargs : bool If True, the result of the dependency task will be passed as a keyword argument. Defaults to False. additional_kwarg_name : str | None The name of the keyword argument to use if use_result_as_additional_kwargs is True. Required when use_result_as_additional_kwargs is True. Defaults to None.
Raises
TypeError If any parameter type is invalid or if use_result_as_additional_kwargs is True but additional_kwarg_name is not a string.
Source code in src/processes/task.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
__hash__()
Return hash of the dependency based on task name.
Returns
int Hash value based on the task_name attribute.
Source code in src/processes/task.py
98 99 100 101 102 103 104 105 106 107 | |
TaskResult
Container for the result of a task execution.
Holds the outcome of running a task, including whether it succeeded, its return value, and any exception that occurred.
Attributes
worked : bool True if the task executed successfully, False if an exception occurred. result : Any The return value of the task's function if execution succeeded, None if failed. exception : Exception | None The exception object if execution failed, None if successful.
Source code in src/processes/task.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |