upxo.meshing.gbconformant.pipeline.background module

Run one stage in a separate process, watch its progress, cancel it at any moment.

The stage runs in a fresh Python process that restores the saved results of the stages before it, runs the stage (which saves its own results), and reports through a file. The caller’s PipelineState is changed only when the stage finishes, by reading the saved results of that stage; a cancelled or failed stage leaves it as it was.

Usage:

job = StageProcess(state, "tet_mesh")      # NotReady if the earlier results are not on disk
job.start()
while not job.done:
    for event in job.poll(): ...           # progress messages
    time.sleep(0.1)
if job.outcome == "finished":
    job.apply()
exception upxo.meshing.gbconformant.pipeline.background.NotReady(reasons)[source]

Bases: Exception

The stage cannot be run in a separate process; reasons say why.

exception upxo.meshing.gbconformant.pipeline.background.IncompleteTransfer[source]

Bases: Exception

The stage ran but some of its results could not be saved, so the caller cannot take them over.

class upxo.meshing.gbconformant.pipeline.background.StageProcess(state: PipelineState, stage_id: str, *, python: str | None = None)[source]

Bases: object

One stage running in its own process.

outcome: str | None

finished, failed, cancelled or crashed once done.

start() → None[source]
property elapsed: float
poll() → list[dict][source]

New events since the last call (progress, then the final one); sets done when the process is over.

cancel() → None[source]

Stop the stage now (the process and anything it started). The caller’s state stays as it was.

property traceback: str
worker_log() → list[str][source]
apply() → None[source]

Take the finished stage’s results into the caller’s state.

record_failure() → None[source]

Show the stage as failed in the caller’s state: status, error text, report and log.

cleanup() → None[source]

Remove the job folder (kept after a failure, for diagnosis).

upxo.meshing.gbconformant.pipeline.background.run_stage_separately(state: PipelineState, stage_id: str, on_event: Callable[[dict], None] | None = None, should_cancel: Callable[[], bool] | None = None, interval: float = 0.1) → StageProcess[source]

Run stage_id in a separate process and wait; the results are in state when the outcome is finished.