Skip to content

Commit 185796d

Browse files
committed
try different method to wait for start
1 parent e9cb5f3 commit 185796d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/idom/server/fastapi.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import asyncio
21
import json
32
import logging
43
import sys
4+
import time
55
import uuid
6-
from threading import Event
6+
from threading import Event, Thread
77
from typing import Any, Dict, Optional, Tuple, Type, Union, cast
88

99
from fastapi import APIRouter, FastAPI, Request, WebSocket
@@ -87,11 +87,13 @@ def _setup_application(self, config: Config, app: FastAPI) -> None:
8787
def _setup_application_did_start_event(
8888
self, config: Config, app: FastAPI, event: Event
8989
) -> None:
90-
@app.on_event("startup")
91-
async def startup_event() -> None:
92-
self._loop = asyncio.get_event_loop()
90+
def target():
91+
while not hasattr(self, "_server") or not self._server.started:
92+
time.sleep(1e-3)
9393
event.set()
9494

95+
Thread(target=target, daemon=True).start()
96+
9597
def _setup_api_router(self, config: Config, router: APIRouter) -> None:
9698
"""Add routes to the application blueprint"""
9799

0 commit comments

Comments
 (0)