Skip to main content

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​

AttributeTypeDescription
limitintThe maximum number of concurrent worker threads allowed in the pool.
body_can_be_bufferboolean = TrueIndicates whether the task payload can be processed as a buffer object.
signal_safeboolean = FalseFlag indicating if the pool implementation can safely handle POSIX signals.

Constructor​

Signature​

def TaskPool(
*args: Any,
**kwargs: Any
) - > None

Parameters​

NameTypeDescription
*argsAnyVariable length argument list passed to the base class constructor.
**kwargsAnyArbitrary 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​

TypeDescription
NoneNothing

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​

NameTypeDescription
targetTargetFunctionThe 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​

TypeDescription
[ApplyResult](applyresult.md?sid=celery_concurrency_thread_applyresult)A handle used to track the execution status and retrieve the result of the submitted task