diff --git a/lidar_pipeline/index.py b/lidar_pipeline/index.py index ce2de03..a142d43 100644 --- a/lidar_pipeline/index.py +++ b/lidar_pipeline/index.py @@ -660,8 +660,8 @@ def generate_thumbnail(src_path, thumb_path, max_size=256, mid_path=None, return source.resize((max(1, int(source.size[0] * scale)), max(1, int(source.size[1] * scale))), resample) - img = PILImage.open(str(src_path)) - img = img.convert('RGB') + with PILImage.open(str(src_path)) as _src_img: + img = _src_img.convert('RGB') Path(thumb_path).parent.mkdir(parents=True, exist_ok=True) if mid_path is not None: try: diff --git a/lidar_pipeline/rendering.py b/lidar_pipeline/rendering.py index b27146a..dd7423b 100644 --- a/lidar_pipeline/rendering.py +++ b/lidar_pipeline/rendering.py @@ -328,6 +328,10 @@ def _download_location_map(min_x, max_x, min_y, max_y): 'min_y': context_min_y, 'max_y': context_max_y, } cached = (result, bounds) + # Éviction FIFO : chaque entrée ~12 Mo (carte ~30 km au zoom 10) — + # un run long sur plusieurs zones ne doit pas empiler sans limite + while len(_location_map_cache) >= 4: + _location_map_cache.pop(next(iter(_location_map_cache))) _location_map_cache[cache_key] = cached return cached @@ -942,7 +946,8 @@ def generate_pdf_report(basename, vis_dir, pdf_dir, resolution): for i, f in enumerate(situ_files): ax = fig.add_subplot(gs[0, i]) - img = np.array(PILImage.open(str(f)).convert('RGB')) + with PILImage.open(str(f)) as _pf: + img = np.array(_pf.convert('RGB')) ax.imshow(img) ax.axis('off') title = f.stem.replace(basename + '_', '').replace('_', ' ').title() @@ -966,7 +971,8 @@ def generate_pdf_report(basename, vis_dir, pdf_dir, resolution): for i, f in enumerate(page_files): ax = fig.add_subplot(gs[0, i]) - img = np.array(PILImage.open(str(f)).convert('RGB')) + with PILImage.open(str(f)) as _pf: + img = np.array(_pf.convert('RGB')) ax.imshow(img) ax.axis('off') title = f.stem.replace(basename + '_', '').replace('_', ' ').title()