register_parallel_side_channel#

tpcp.parallel.register_parallel_side_channel(capture: Callable[[], Any], restore: Callable[[Any], AbstractContextManager[Callable[[], Any]]], merge: Callable[[Any], None], name: str | None = None) str[source]#

Register state that can make a round trip through a parallel worker.

capture is called when delayed creates a task. If it returns None, the side channel is inactive for that task. Otherwise, restore receives the captured state in the worker and must return a context manager. The callable yielded by that context manager is invoked after a successful task to collect side-channel data. When Parallel consumes the task result, merge receives that data in the parent process.

Plain joblib.Parallel still enters the worker context, but does not collect or merge side-channel data. A task that raises does not return its side-channel data either.

Parameters:
capture

Capture parent-process state for one delayed task. Return None to disable this side channel for that task.

restore

Create the context manager that restores the captured state around one worker task. It must yield a zero-argument collector callable.

merge

Merge the collector result into parent-process state.

name

Optional registration name used to remove the side channel again. Names beginning with "__tpcp_internal__." are reserved for TPCP.

Returns:
str

The registration name for remove_parallel_side_channel.