Skip to content

yggdrasil.concurrent.threading.thread_job

thread_job

ThreadJob — daemon-thread-backed implementation of AsyncJob.

ThreadJob dataclass

ThreadJob(job: Job[T])

Bases: AsyncJob[T]

A :class:~yggdrasil.concurrent.job.Job running in a daemon :class:~threading.Thread, started immediately on construction.

Use :meth:wait to block and retrieve the result::

handle = Job.make(fetch_data, url).fire_and_forget()

# … do other work …

data = handle.wait()           # block until thread finishes
data = handle.wait(wait=5.0)   # block at most 5 seconds
data = handle.wait(wait=False) # non-blocking poll

is_done property

is_done: bool

True when the thread has finished (success or failure).

result

result() -> Optional[JobResult[T]]

Return the :class:~yggdrasil.concurrent.job_result.JobResult if done, else None.

wait

wait(wait: WaitingConfigArg = None, raise_error: bool = True) -> Optional[T]

Block until the thread finishes.

Parameters:

Name Type Description Default
wait WaitingConfigArg

None / True → block indefinitely. False → non-blocking poll. WaitingConfig or numeric seconds → timed wait.

None
raise_error bool

Re-raise the thread's exception when True.

True

Returns:

Type Description
Optional[T]

The job return value, or None on failure / timeout / non-blocking

Optional[T]

miss (when raise_error=False).

Raises:

Type Description
TimeoutError

When a timed wait elapses before the thread finishes.

BaseException

The exception from the job (when raise_error=True).