Merge pull request #24 from optuna/fix-cache

Fix a bug of trials cache
This commit is contained in:
Masashi SHIBATA
2021-01-25 22:48:24 +09:00
committed by GitHub
2 changed files with 6 additions and 5 deletions
+3 -4
View File
@@ -9,7 +9,7 @@ from typing import Union, Dict, List, Optional, TypeVar, Callable, Any, cast
from bottle import Bottle, BaseResponse, redirect, request, response, static_file
from optuna.exceptions import DuplicatedStudyError
from optuna.storages import BaseStorage, get_storage
from optuna.storages import BaseStorage
from optuna.trial import FrozenTrial
from optuna.study import StudyDirection, StudySummary
@@ -84,7 +84,7 @@ def get_trials(
if (
trials is not None
and last_fetched_at is not None
and datetime.now() - last_fetched_at < timedelta(ttl_seconds)
and datetime.now() - last_fetched_at < timedelta(seconds=ttl_seconds)
):
return trials
trials = storage.get_all_trials(study_id)
@@ -94,9 +94,8 @@ def get_trials(
return trials
def create_app(storage_or_url: Union[str, BaseStorage]) -> Bottle:
def create_app(storage: BaseStorage) -> Bottle:
app = Bottle()
storage = get_storage(storage_or_url)
@app.hook("before_request")
def remove_trailing_slashes_hook() -> None:
+3 -1
View File
@@ -2,6 +2,7 @@ import argparse
import os
from bottle import run
from optuna.storages import RDBStorage
from .app import create_app
from .version import __version__
@@ -23,7 +24,8 @@ def main() -> None:
parser.add_argument("--quiet", "-q", help="quiet", action="store_true")
args = parser.parse_args()
app = create_app(args.storage)
storage = RDBStorage(args.storage)
app = create_app(storage)
run(app, host=args.host, port=args.port, quiet=args.quiet, reloader=AUTO_RELOAD)