Skip to content

Commit e138a73

Browse files
committed
fix: memory leak in periodic sync - clear futures and force GC
- Change futures dict to list (mapping not used) - Explicitly del futures after as_completed() to release references - Add gc.collect() after each periodic sync cycle to return arenas to OS - Bump version to 0.4.1
1 parent 4963c4e commit e138a73

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "audio-transcode-watcher"
7-
version = "0.4.0"
7+
version = "0.4.1"
88
description = "Watch a source folder and automatically transcode audio files to multiple formats"
99
readme = "README.md"
1010
license = "GPL-3.0-or-later"

‎src/audio_transcode_watcher/main.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import gc
56
import logging
67
import os
78
import sys
@@ -83,6 +84,7 @@ def main() -> int:
8384
if time.time() - last_sync >= sync_interval:
8485
logger.info("Periodic sync check…")
8586
initial_sync(config)
87+
gc.collect()
8688
last_sync = time.time()
8789
except KeyboardInterrupt:
8890
observer.stop()

‎src/audio_transcode_watcher/sync.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,10 @@ def process_one(src_file: str) -> None:
385385
logger.error("Error processing %s: %s", src_file, e)
386386

387387
with ThreadPoolExecutor(max_workers=workers) as executor:
388-
futures = {executor.submit(process_one, f): f for f in source_files}
388+
futures = [executor.submit(process_one, f) for f in source_files]
389389
for future in as_completed(futures):
390-
# Just wait for completion, errors are logged in process_one
391390
pass
391+
del futures
392392

393393
# Remove orphans
394394
if safety_guard_active(config):

0 commit comments

Comments
 (0)