Context
Execution context for DAG runs.
Context management for DAG execution, including sync/async context wrappers.
AsyncContext
Bases: AsyncDataWhiteBoard, AsyncTaskState
Asynchronous wrapper around Context for async-safe operations.
Source code in shutils/dag/context.py
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 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 | |
context
property
Access the underlying core context.
id
property
Unique identifier of the context.
sync_context
property
Access the sync context wrapper for the same core context.
__init__(context)
Initialize with the underlying context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
Context
|
The core context object. |
required |
Source code in shutils/dag/context.py
218 219 220 221 222 223 224 225 226 | |
child_context_num()
async
Get the number of child contexts.
Source code in shutils/dag/context.py
292 293 294 295 | |
complete(task)
async
Mark a task as completed and propagate to the parent context.
Source code in shutils/dag/context.py
353 354 355 356 357 | |
create(copy_data=False, deep_copy=False, name='', skip_complete=False)
async
Create a new context, optionally copying data from this one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
copy_data
|
bool
|
Whether to copy data to the new context. |
False
|
deep_copy
|
bool
|
Whether to deep-copy data instead of sharing references. |
False
|
name
|
str
|
Optional name for the new context. |
''
|
skip_complete
|
bool
|
If True, skip completion tracking for the new context. |
False
|
Returns:
| Type | Description |
|---|---|
AsyncContext
|
The async wrapper of the new context. |
Source code in shutils/dag/context.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
create_child(num=0, name=None)
async
create_child(num: int = 0, name: str | None = None) -> AsyncContext
create_child(num: int, name: str | list[str] | None = None) -> list[AsyncContext]
Create one or more child contexts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
int
|
Number of children to create. 0 creates a single child. |
0
|
name
|
str | list[str] | None
|
Optional name(s) for the children. |
None
|
Returns:
| Type | Description |
|---|---|
AsyncContext | list[AsyncContext]
|
A single AsyncContext if num is 0, otherwise a list of AsyncContexts. |
Source code in shutils/dag/context.py
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 | |
destory(destory_parent=False)
async
Destroy the context and release runtime resources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
destory_parent
|
bool
|
If True, also destroy the parent when this is its last child. |
False
|
Source code in shutils/dag/context.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
freeze()
Freeze the context to prevent it from being scheduled.
Source code in shutils/dag/context.py
243 244 245 | |
iter_child_context()
async
Iterate over child contexts under an async read lock.
Source code in shutils/dag/context.py
297 298 299 300 301 | |
parent_context()
async
Get the parent context, or None if this is a root context.
Source code in shutils/dag/context.py
303 304 305 306 307 308 309 | |
thraw()
Unfreeze the context to allow scheduling again.
Source code in shutils/dag/context.py
247 248 249 | |
Context
Bases: DataWhiteBoardMixin, TaskStateMixin
Core context object carrying data and task state through the DAG.
Source code in shutils/dag/context.py
32 33 34 35 36 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 | |
async_context
property
Lazy accessor for the async context wrapper.
sync_context
property
Lazy accessor for the sync context wrapper.
__init__(runtime, parent=None, name='')
Initialize a context with optional runtime, parent, and name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runtime
|
Runtime | None
|
The runtime for tracking active context count. |
required |
parent
|
Context | None
|
Optional parent context for hierarchical contexts. |
None
|
name
|
str
|
Optional context name; defaults to a UUID. |
''
|
Source code in shutils/dag/context.py
35 36 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 | |
LoopContext
Bases: Context
Context used for loop tasks, pre-activating the loop task.
Source code in shutils/dag/context.py
360 361 362 363 364 365 366 367 368 369 370 371 372 | |
__init__(runtime, task, name='LoopContext')
Initialize a LoopContext with the loop task already available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runtime
|
Runtime | None
|
The runtime for tracking active context count. |
required |
task
|
TaskBase
|
The loop task to make immediately available. |
required |
name
|
str
|
Optional context name. |
'LoopContext'
|
Source code in shutils/dag/context.py
363 364 365 366 367 368 369 370 371 372 | |
OutputContext
Bases: Context
Terminal context that holds the final output of DAG execution.
Source code in shutils/dag/context.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
__init__(context=None, name='OutputContext')
Initialize an OutputContext, optionally copying data from another context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
Context | None
|
Optional source context to copy ID and data from. |
None
|
name
|
str
|
Optional context name. |
'OutputContext'
|
Source code in shutils/dag/context.py
400 401 402 403 404 405 406 407 408 409 410 | |
acopy(context)
async
Async copy ID and data from another context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
Context
|
The source context to copy from. |
required |
Source code in shutils/dag/context.py
412 413 414 415 416 417 418 419 | |
asdit()
Return the raw data dictionary.
Source code in shutils/dag/context.py
422 423 424 | |
RateLimitContext
Bases: Context
Context wrapper indicating a rate-limit throttle event.
Source code in shutils/dag/context.py
375 376 377 378 379 380 381 382 383 384 385 386 | |
__init__(context)
Initialize from an existing context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
Context
|
The original context that was rate-limited. |
required |
Source code in shutils/dag/context.py
378 379 380 381 382 383 384 385 386 | |
StopContext
Bases: Context
Signal context that instructs workers to stop processing.
Source code in shutils/dag/context.py
389 390 391 392 393 394 | |
__init__(name='StopContext')
Initialize a stop signal context.
Source code in shutils/dag/context.py
392 393 394 | |
SyncContext
Bases: SyncDataWhiteBoard, SyncTaskState
Synchronous wrapper around Context for thread-safe operations.
Source code in shutils/dag/context.py
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 | |
async_context
property
Access the async context wrapper for the same core context.
context
property
Access the underlying core context.
id
property
Unique identifier of the context.
__init__(context)
Initialize with the underlying context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
Context
|
The core context object. |
required |
Source code in shutils/dag/context.py
105 106 107 108 109 110 111 112 113 | |
child_context_num()
Get the number of child contexts.
Source code in shutils/dag/context.py
179 180 181 182 | |
complete(task)
Mark a task as completed and propagate to the parent context.
Source code in shutils/dag/context.py
208 209 210 211 212 | |
create(copy_data=False, deep_copy=False, name='', skip_complete=False)
Create a new context, optionally copying data from this one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
copy_data
|
bool
|
Whether to copy data to the new context. |
False
|
deep_copy
|
bool
|
Whether to deep-copy data instead of sharing references. |
False
|
name
|
str
|
Optional name for the new context. |
''
|
skip_complete
|
bool
|
If True, skip completion tracking for the new context. |
False
|
Returns:
| Type | Description |
|---|---|
SyncContext
|
The sync wrapper of the new context. |
Source code in shutils/dag/context.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
create_child(num=0)
Create one or more child contexts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
int
|
Number of children to create. 0 creates a single child. |
0
|
Returns:
| Type | Description |
|---|---|
list[SyncContext] | SyncContext
|
A single SyncContext if num is 0, otherwise a list of SyncContexts. |
Source code in shutils/dag/context.py
194 195 196 197 198 199 200 201 202 203 204 205 206 | |
destory(destory_parent=False)
Destroy the context and release runtime resources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
destory_parent
|
bool
|
If True, also destroy the parent when this is its last child. |
False
|
Source code in shutils/dag/context.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
freeze()
Freeze the context to prevent it from being scheduled.
Source code in shutils/dag/context.py
130 131 132 | |
iter_child_context()
Iterate over child contexts under a read lock.
Source code in shutils/dag/context.py
184 185 186 187 | |
parent_context()
Get the parent context.
Source code in shutils/dag/context.py
189 190 191 192 | |
thraw()
Unfreeze the context to allow scheduling again.
Source code in shutils/dag/context.py
134 135 136 | |