[Bug] Pillow-Resource-Leak: Image.open() ohne with-Statement #18

Closed
opened 2026-05-27 12:21:05 +02:00 by ferdi2go · 1 comment
Owner

Problem

analyzer.py:21, analyzer.py:66:

def _mean_brightness(path: str) -> float:
    img = Image.open(path).convert("L")  # File-Handle bleibt offen
    arr = np.array(img, dtype=np.float32)
    return float(arr.mean())

# und in find_duplicates():
h = imagehash.phash(Image.open(path))

Bei vielen Bildern -> OSError: [Errno 24] Too many open files.

Fix

with Image.open(path) as img:
    img = img.convert("L")
    arr = np.array(img, dtype=np.float32)
return float(arr.mean())

Alle Image.open()-Stellen in analyzer.py und processor.py pruefen.

## Problem `analyzer.py:21`, `analyzer.py:66`: ```python def _mean_brightness(path: str) -> float: img = Image.open(path).convert("L") # File-Handle bleibt offen arr = np.array(img, dtype=np.float32) return float(arr.mean()) # und in find_duplicates(): h = imagehash.phash(Image.open(path)) ``` Bei vielen Bildern -> OSError: [Errno 24] Too many open files. ## Fix ```python with Image.open(path) as img: img = img.convert("L") arr = np.array(img, dtype=np.float32) return float(arr.mean()) ``` Alle `Image.open()`-Stellen in analyzer.py und processor.py pruefen.
ferdi2go added the bugpriority: high labels 2026-05-27 12:21:05 +02:00
Author
Owner

Fix umgesetzt:

  • analyzer.py:_mean_brightness -> with Image.open(...)
  • analyzer.py:find_duplicates -> with Image.open(...) as img: phash(img)
  • processor.py:get_exif_info -> with Image.open(...)
  • processor.py:apply_image_watermark -> with Image.open(wm_path) as wm_src
  • processor.py:process_photo -> with Image.open() as src: src.load(); img = src.copy() (Copy noetig weil img nach with weiter verwendet wird)
  • server.py HEIC-Konvertierung -> with Image.open(io.BytesIO(raw)) as src

Manueller Test: 3 Bilder analysiert, FD-Count stabil bei 15.

Fix umgesetzt: - `analyzer.py:_mean_brightness` -> `with Image.open(...)` - `analyzer.py:find_duplicates` -> `with Image.open(...) as img: phash(img)` - `processor.py:get_exif_info` -> `with Image.open(...)` - `processor.py:apply_image_watermark` -> `with Image.open(wm_path) as wm_src` - `processor.py:process_photo` -> `with Image.open() as src: src.load(); img = src.copy()` (Copy noetig weil img nach with weiter verwendet wird) - `server.py` HEIC-Konvertierung -> `with Image.open(io.BytesIO(raw)) as src` Manueller Test: 3 Bilder analysiert, FD-Count stabil bei 15.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ferdi2go/OnlyFrames#18