Fermer les images PIL et borner le cache de cartes de localisation

This commit is contained in:
Antoine Jacquin
2026-09-18 21:20:14 +02:00
parent 394dd27375
commit 5e13151998
2 changed files with 10 additions and 4 deletions

View File

@ -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:

View File

@ -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()