fastapiのmain.pyを起動すると自動的に10秒おきに"hello"を自動的に表示するコードを作って下さい。2024年1月29日import asyncio from fastapi import FastAPI app = FastAPI() async def hello_timer(): while True: print("hello") await asyncio.sleep(10) # 10秒待機 @app.on_event("startup") async def startup_event(): # FastAPIアプリケーションの起動時にタイマーを開始 asyncio.create_task(hello_timer()) @app.get("/") async def get_hello(): return {"message": "hello"}CopyPythonCopy 2024年1月29日2024,江端さんの技術メモPosted by ebata