gui.jobs.InProcessJob(function)
A function that runs in a worker thread, one run at a time that counts.
Every start bumps a generation counter. A result of an older generation is dropped, so a slow run that the user has already replaced never overwrites the newer answer.
Examples
from pathlib import Path
from tempfile import TemporaryDirectory
from spotregen import load_spec, make_sample_repo, run_checks
from spotregen.gui.jobs import InProcessJob
with TemporaryDirectory() as tmp:
spec = load_spec(make_sample_repo(Path(tmp) / "demo" ))
job = InProcessJob(run_checks)
job.start(spec)
print (job.wait().value)
Attributes
running
Whether the latest run has not finished.
Methods
poll
The result of the latest run if it is ready, else None. Never blocks.
start
Run the function with these arguments in a new daemon thread.
wait
Block until the latest run has finished; meant for scripts and tests.
poll
gui.jobs.InProcessJob.poll()
The result of the latest run if it is ready, else None. Never blocks.
Returns
JobResult | None
JobResult | None: The newest finished result; results of older runs are discarded.
start
gui.jobs.InProcessJob.start(* args, ** kwargs)
Run the function with these arguments in a new daemon thread.
Parameters
*args
Any
Positional arguments of the function.
()
**kwargs
Any
Keyword arguments of the function.
{}
Returns
int
int
The generation of this run.
wait
gui.jobs.InProcessJob.wait(timeout= 30.0 )
Block until the latest run has finished; meant for scripts and tests.
Parameters
timeout
float
Seconds to wait.
30.0
Returns
JobResult
JobResult
The result of the latest run.