Skip to content

Python

Python dataclass

Python(name: str, function: Callable[..., Any], cores: int = 1, *, kwargs: Mapping[str, Any] = dict())

Run function(context, **kwargs) in its own process.

Use an importable function and pickleable argument values. Context is passed by the runner; kwargs supplies task-specific values, not workflow inputs.

Parameters:

Name Type Description Default
name str

Unique directory-safe task name within its stage.

required
function Callable

Top-level callback accepting context as its first argument.

required
cores int

Positive core reservation; this does not parallelize the callback.

1
kwargs Mapping[str, Any]

Keyword arguments passed to the callback.

dict()

Raises:

Type Description
ValueError

Name or core reservation is invalid.

TypeError

The callback is not callable or kwargs is not a string-keyed mapping.

Example
from femora.jobs.tasks import Python
def report(context, label):
    return {"label": label, "workspace": str(context.workspace)}
task = Python("report", report, kwargs={"label": "case-a"})
Note

Return values must be transferable between processes. Keep callback functions importable and protect execution with a main guard. The TACC backend permits Python callbacks only in sequential stages with cores=1.