TaskPool
This class implements a thread-based task pool using a thread pool executor to manage concurrent execution. It provides mechanisms to submit tasks with optional callbacks and ensures proper resource cleanup by shutting down the executor when the pool is stopped. The class also tracks pool-specific metadata such as maximum concurrency and the current number of active threads.
Attributes
| Attribute | Type | Description |
|---|---|---|
| limit | int | The maximum number of concurrent worker threads allowed in the pool. |
| body_can_be_buffer | boolean = True | Indicates whether the task payload can be processed as a buffer object. |
| signal_safe | boolean = False | Flag indicating if the pool implementation can safely handle POSIX signals. |
Constructor
Signature
def TaskPool(
*args: Any,
**kwargs: Any
) - > None
Parameters
| Name | Type | Description |
|---|---|---|
| *args | Any | Variable length argument list passed to the base class constructor. |
| **kwargs | Any | Arbitrary keyword arguments passed to the base class constructor. |
Methods
on_stop()
@classmethod
def on_stop() - > None
Shuts down the underlying thread pool executor and cancels any pending futures before calling the base stop logic.
Returns
| Type | Description |
|---|---|
None | Nothing |
on_apply()
@classmethod
def on_apply(
target: TargetFunction,
args: tuple[Any, ...]| None,
kwargs: dict[str, Any]| None,
callback: Callable[..., Any]| None,
accept_callback: Callable[..., Any]| None
) - > [ApplyResult](applyresult.md?sid=celery_concurrency_thread_applyresult)
Submits a target function for execution within the thread pool and returns an object to track the result.
Parameters
| Name | Type | Description |
|---|---|---|
| target | TargetFunction | The callable function or task to be executed by a worker thread |
| args | `tuple[Any, ...] | None` |
| kwargs | `dict[str, Any] | None` |
| callback | `Callable[..., Any] | None` |
| accept_callback | `Callable[..., Any] | None` |
Returns
| Type | Description |
|---|---|
[ApplyResult](applyresult.md?sid=celery_concurrency_thread_applyresult) | A handle used to track the execution status and retrieve the result of the submitted task |