Skip to content

Commit

Permalink
FIX: 非推奨のstartupイベントをlifespanに置き換え (#1131)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabonerune authored Mar 22, 2024
1 parent d81ba0f commit 0269fac
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import sys
import traceback
import zipfile
from collections.abc import Awaitable, Callable
from collections.abc import AsyncIterator, Awaitable, Callable
from contextlib import asynccontextmanager
from functools import lru_cache
from io import BytesIO, TextIOWrapper
from pathlib import Path
Expand Down Expand Up @@ -148,10 +149,16 @@ def generate_app(
if root_dir is None:
root_dir = engine_root()

@asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
update_dict()
yield

app = FastAPI(
title="VOICEVOX Engine",
description="VOICEVOXの音声合成エンジンです。",
version=__version__,
lifespan=lifespan,
)

# 未処理の例外が発生するとCORSMiddlewareが適用されない問題に対するワークアラウンド
Expand Down Expand Up @@ -250,10 +257,6 @@ def check_disabled_mutable_api() -> None:
# loop = asyncio.get_event_loop()
# _ = loop.create_task(cancellable_engine.catch_disconnection())

@app.on_event("startup")
def apply_user_dict() -> None:
update_dict()

def get_engine(core_version: Optional[str]) -> TTSEngine:
if core_version is None:
return tts_engines[latest_core_version]
Expand Down

0 comments on commit 0269fac

Please sign in to comment.