Skip to content

yggdrasil.concurrent.job

job

Job — minimal callable bundle.

Thread-specific classes (AsyncJob, ThreadJob) live in :mod:yggdrasil.concurrent.threading.

Job

Job(
    func: Callable[..., T],
    args: Tuple[Any, ...] = _EMPTY_ARGS,
    kwargs: Dict[str, Any] = _EMPTY_KWARGS,
)

Bases: Generic[T]

Minimal callable bundle: a function plus its bound args / kwargs.

Deliberately not a :func:dataclass. Job is on the hot path for every fan-out (JobPoolExecutor.as_completed), every fire-and-forget thread spawn, and every retry layer — the saved dataclass init / equality / repr overhead matters per job. A plain slotted class with a hand-written __init__ is roughly half the per-construction cost.

Build via :meth:make (collects *args / **kwargs like a normal call site) or pass them explicitly to the constructor.

Usage::

job = Job.make(my_func, arg1, arg2, key=val)
result = job.run()                # synchronous
handle = job.fire_and_forget()    # background thread, returns ThreadJob
handle.wait()                     # block until done

make classmethod

make(func: Callable[..., T], *args: Any, **kwargs: Any) -> 'Job[T]'

Build a :class:Job from a callable and its arguments.

run

run() -> T

Execute the job synchronously in the calling thread.

thread

thread() -> 'ThreadJob[T]'

Start this job in a daemon thread and return a :class:~yggdrasil.concurrent.threading.ThreadJob handle.

The thread is started immediately. Call :meth:~yggdrasil.concurrent.threading.ThreadJob.wait to block until completion and retrieve the result.

fire_and_forget

fire_and_forget() -> 'ThreadJob[T]'

Alias for :meth:thread — kept for the more readable call site.