From 837f389950b5304b281d0f9c7dd63dfbea168801 Mon Sep 17 00:00:00 2001 From: Zhaofeng Zhang <24791380+vcfgv@users.noreply.github.com> Date: Tue, 2 Dec 2025 10:47:30 +0800 Subject: [PATCH] fix(main): disable control thread for local development environment --- python/valuecell/server/main.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/python/valuecell/server/main.py b/python/valuecell/server/main.py index c009f275f..6e075df3a 100644 --- a/python/valuecell/server/main.py +++ b/python/valuecell/server/main.py @@ -3,6 +3,7 @@ from __future__ import annotations import io +import os import sys import threading from typing import Callable, Optional, TextIO @@ -66,13 +67,23 @@ def request_stop() -> None: server.should_exit = True logger.info("Shutdown signal propagated to uvicorn") - control_thread = threading.Thread( - target=control_loop, - name="stdin-control", - args=(request_stop,), - daemon=True, - ) - control_thread.start() + # In local development / IDE debug mode (ENV=local_dev) the interactive + # stdin wrapper (e.g. PyCharm debug) can cause attribute errors when + # iterating over `sys.stdin`. Skip creating the control thread in that + # environment to avoid crashing the background thread. + if os.getenv("ENV") == "local_dev": + logger.info( + "ENV=local_dev detected: skipping stdin control thread (IDE debug mode)" + ) + control_thread = None + else: + control_thread = threading.Thread( + target=control_loop, + name="stdin-control", + args=(request_stop,), + daemon=True, + ) + control_thread.start() try: server.run()