Isolate STL analysis in child process; fix 3MF memory usage

- _load_geometry(): compute extents/volume from individual Scene meshes
  without concatenating — avoids the RAM spike that crashed the container
- analyse_in_background(): spawns a child process (spawn context, not fork)
  with a 120s timeout; OOM/crash in child no longer takes down the app
- _failed set: tracks files that timed out or crashed; spinner stops and
  a warning with inline override form is shown instead of looping forever
- analysis_failed state passed to template; override form shown immediately
  when analysis failed (no expand needed)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Martin Hohenberg
2026-06-19 11:32:15 +02:00
parent 6a1f146d8e
commit dc8918d323
3 changed files with 89 additions and 18 deletions

View File

@@ -26,7 +26,7 @@ from app.estimation import estimate # also used in start_job
from app.filamentdb import (available_colors, available_materials, find_matching_ams_roll,
get_stock, log_print_on_roll, spool_counts)
from app.stl import get_stl_dir, list_stl_files
from app.stl_analysis import analyse_in_background, get_cache_map, is_computing # noqa: F401
from app.stl_analysis import analyse_in_background, get_cache_map, is_computing, is_failed # noqa: F401
router = APIRouter()
templates = Jinja2Templates(directory="app/templates")
@@ -276,9 +276,11 @@ def job_detail(job_id: int, request: Request, background_tasks: BackgroundTasks,
else:
stl = db.query(StlCache).filter_by(filename=job.file_name).first()
if stl is None and not job.file_name.endswith(".gcode"):
if not is_computing(job.file_name):
if is_failed(job.file_name):
file_missing = False # file exists, analysis just failed
elif not is_computing(job.file_name):
background_tasks.add_task(analyse_in_background, job.file_name)
computing = True
computing = not is_failed(job.file_name)
estimation = estimate(stl.volume_ccm, job.job_material) if stl and stl.volume_ccm else None
return templates.TemplateResponse("job_detail.html", {
@@ -288,6 +290,7 @@ def job_detail(job_id: int, request: Request, background_tasks: BackgroundTasks,
"stl": stl,
"file_missing": file_missing,
"computing": computing,
"analysis_failed": job.file_name and is_failed(job.file_name),
"estimation": estimation,
"printers": db.query(Printer).order_by(Printer.name).all(),
"brackets": db.query(JobBracket).order_by(JobBracket.name).all(),