Skip to content

Commit 3b3e9c0

Browse files
committed
fix tmp removal
1 parent 095a5cb commit 3b3e9c0

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

openevolve/controller.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import asyncio
66
import logging
77
import os
8+
import shutil
89
import re
910
import time
1011
import uuid
@@ -216,7 +217,7 @@ async def run(
216217
self.database.log_island_status()
217218

218219
# create temp file to save database snapshots to for process workers to load from
219-
temp_db_path = "temp/" + str(uuid.uuid4())
220+
temp_db_path = "tmp/" + str(uuid.uuid4())
220221
self.database.save(temp_db_path, start_iteration)
221222

222223
with concurrent.futures.ProcessPoolExecutor(
@@ -293,7 +294,7 @@ async def run(
293294
except Exception:
294295
logger.exception(f"Error in iteration {iteration}:")
295296
continue
296-
os.rmdir(temp_db_path)
297+
shutil.rmtree(temp_db_path)
297298

298299
# Get the best program using our tracking mechanism
299300
best_program = None

openevolve/database.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import time
1111
from dataclasses import asdict, dataclass, field
1212
from pathlib import Path
13-
from Levenshtein import distance, ratio
13+
from Levenshtein import ratio
1414
from filelock import FileLock, Timeout
1515
from typing import Any, Dict, List, Optional, Set, Tuple, Union
1616

@@ -307,7 +307,8 @@ def save(self, path: Optional[str] = None, iteration: int = 0) -> None:
307307
logger.warning("No database path specified, skipping save")
308308
return
309309

310-
lock_path = save_path + ".lock"
310+
lock_name = os.path.basename(save_path) + '.lock'
311+
lock_path = os.path.join('tmp/locks', lock_name)
311312
try:
312313
with FileLock(lock_path, timeout=10):
313314
# Create directory and remove old path if it exists
@@ -371,7 +372,8 @@ def load(self, path: str) -> None:
371372
logger.info(f"Loaded database metadata with last_iteration={self.last_iteration}")
372373

373374
# Load programs
374-
lock_path = path + ".lock"
375+
lock_name = os.path.basename(path) + '.lock'
376+
lock_path = os.path.join('tmp/locks', lock_name)
375377
programs_dir = os.path.join(path, "programs")
376378
try:
377379
with FileLock(lock_path, timeout=10):

0 commit comments

Comments
 (0)