ThreadGroup
Base classes¶
| Name | Children | Inherits |
|---|---|---|
| Generic typing Abstract base class for generic types. |
⋔ Inheritance diagram¶
graph TD
2492307227["threadgroup.ThreadGroup"]
3481597255["typing.Generic"]
2751680898["builtins.object"]
3481597255 --> 2492307227
2751680898 --> 3481597255
🛈 DocStrings¶
Class that executes functions in parallel, with TaskGroup-like API.
Source code in src/anyenv/calling/threadgroup.py
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 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 | |
__aenter__
async
¶
__aenter__() -> ThreadGroup[R]
__aexit__
async
¶
__aexit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None
Exit the async context manager, waiting without blocking the event loop.
Source code in src/anyenv/calling/threadgroup.py
__enter__
¶
__enter__() -> ThreadGroup[R]
__exit__
¶
__exit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None
Exit the context manager: wait for all tasks and shut the executor down.
Results are collected in spawn order. On the first failure (with
raise_exceptions) tasks that haven't started are cancelled, the running
ones are waited for, then the first failure in spawn order is raised.
Source code in src/anyenv/calling/threadgroup.py
__init__
¶
__init__(
max_workers: int | None = None, raise_exceptions: bool = True, preserve_context: bool = False
) -> None
Thread task group that executes functions in parallel.
Supports both sync and async context managers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_workers
|
int | None
|
Maximum number of worker threads |
None
|
raise_exceptions
|
bool
|
If True, raises exceptions from tasks |
True
|
preserve_context
|
bool
|
If True, preserves context variables across threads |
False
|
Source code in src/anyenv/calling/threadgroup.py
shutdown
¶
spawn
¶
Submit a task immediately to the executor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., R]
|
The function to execute |
required |
*args
|
Any
|
Positional arguments to pass to the function |
()
|
**kwargs
|
Any
|
Keyword arguments to pass to the function |
{}
|
Returns:
| Type | Description |
|---|---|
Future[R]
|
Future object representing the execution of the function |