GitHub

python_worker

API reference for python_worker.

The parent side of Python workers (Effect's NodeWorker).

layer(spawn) provides the WorkerPlatform and a Spawner giving, for each worker id, a ThreadWorker(target) (a function run on a thread of its own, which runs its own runtime) or a ProcessWorker(args) (a child Python process). The code in the worker serves its parent with python_worker_runner.layer. Closing a run's scope asks the worker to close and waits up to five seconds for it to exit before killing it::

platform = python_worker.layer(lambda _: ProcessWorker(["-m", "app.worker"]))

A worker that exits, raises or sends a message that cannot be read fails its run with a WorkerError (WorkerReceiveError); one that cannot start fails it with a WorkerSpawnError.

Re-exports

Values

AttributeTypeDescription
CLOSE_TIMEOUTLiteral['5 seconds'] = '5 seconds'

Seconds a closing worker gets to exit before it is killed.

layer_platformLayer[WorkerPlatform]

The WorkerPlatform for ThreadWorker and ProcessWorker.

Functions

layer

layer(spawn) -> Layer[WorkerPlatform | Spawner]

layer_platform with spawn as the Spawner.

ParameterTypeDescription
spawnCallable[[int], WorkerHandle]

Returns Layer[WorkerPlatform | Spawner]

def layer(spawn: Callable[[int], WorkerHandle]) -> Layer[WorkerPlatform | Spawner]:
    """``layer_platform`` with ``spawn`` as the ``Spawner``."""
    return merge(layer_spawner(spawn), layer_platform)