fix: Use file instead of symlink lock (for windows) (#116)

This commit is contained in:
anrp
2026-01-25 14:04:01 +00:00
committed by GitHub
parent 451db0b76e
commit 42f5a9b553
+4 -3
View File
@@ -28,7 +28,7 @@ from optuna import Trial, TrialPruned
from optuna.exceptions import ExperimentalWarning from optuna.exceptions import ExperimentalWarning
from optuna.samplers import TPESampler from optuna.samplers import TPESampler
from optuna.storages import JournalStorage from optuna.storages import JournalStorage
from optuna.storages.journal import JournalFileBackend from optuna.storages.journal import JournalFileBackend, JournalFileOpenLock
from optuna.study import StudyDirection from optuna.study import StudyDirection
from optuna.trial import TrialState from optuna.trial import TrialState
from pydantic import ValidationError from pydantic import ValidationError
@@ -257,7 +257,8 @@ def run():
) )
os.makedirs(settings.study_checkpoint_dir, exist_ok=True) os.makedirs(settings.study_checkpoint_dir, exist_ok=True)
backend = JournalFileBackend(study_checkpoint_file) lock_obj = JournalFileOpenLock(study_checkpoint_file)
backend = JournalFileBackend(study_checkpoint_file, lock_obj=lock_obj)
storage = JournalStorage(backend) storage = JournalStorage(backend)
try: try:
@@ -302,7 +303,7 @@ def run():
) )
elif choice == "restart": elif choice == "restart":
os.unlink(study_checkpoint_file) os.unlink(study_checkpoint_file)
backend = JournalFileBackend(study_checkpoint_file) backend = JournalFileBackend(study_checkpoint_file, lock_obj=lock_obj)
storage = JournalStorage(backend) storage = JournalStorage(backend)
else: else:
print("Cancelled; exiting.") print("Cancelled; exiting.")