Skip to content

Commit 12ec78a

Browse files
author
Dylan Huang
committed
fix "uvicorn eval_protocol.utils.logs_server:create_app --factory --reload"
1 parent dbd1759 commit 12ec78a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

eval_protocol/utils/logs_server.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ def _handle_event(self, event_type: str, data: Any) -> None:
288288
data = EvaluationRow(**data)
289289
self.websocket_manager.broadcast_row_upserted(data)
290290

291+
def start_loops(self):
292+
"""Start the broadcast loop and evaluation watcher."""
293+
self.websocket_manager.start_broadcast_loop()
294+
self.evaluation_watcher.start()
295+
291296
async def run_async(self):
292297
"""
293298
Run the logs server asynchronously with file watching.
@@ -300,11 +305,7 @@ async def run_async(self):
300305
logger.info(f"Serving files from: {self.build_dir}")
301306
logger.info("WebSocket endpoint available at /ws")
302307

303-
# Start the broadcast loop
304-
self.websocket_manager.start_broadcast_loop()
305-
306-
# Start the evaluation watcher
307-
self.evaluation_watcher.start()
308+
self.start_loops()
308309

309310
config = uvicorn.Config(
310311
self.app,
@@ -336,24 +337,26 @@ def run(self):
336337

337338
def create_app(host: str = "localhost", port: int = 8000, build_dir: Optional[str] = None) -> FastAPI:
338339
"""
339-
Factory function to create a FastAPI app instance.
340+
Factory function to create a FastAPI app instance and start the server with async loops.
340341
341-
This allows uvicorn to call it with parameters and avoids top-level variable instantiation.
342+
This creates a LogsServer instance and starts it in a background thread to ensure
343+
all async loops (WebSocket broadcast, evaluation watching) are running.
342344
343345
Args:
344346
host: Host to bind to
345347
port: Port to bind to
346348
build_dir: Optional custom build directory path
347349
348350
Returns:
349-
FastAPI app instance
351+
FastAPI app instance with server running in background
350352
"""
351353
if build_dir is None:
352354
build_dir = os.path.abspath(
353355
os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "vite-app", "dist")
354356
)
355357

356358
server = LogsServer(host=host, port=port, build_dir=build_dir)
359+
server.start_loops()
357360
return server.app
358361

359362

0 commit comments

Comments
 (0)