DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
improve install scripts and session management
Bingxi Zhaob9cd3ed4c659
diff --git a/scripts/install_all.py b/scripts/install_all.pyindex fa248e9ef..e3ce35996 100644--- a/scripts/install_all.py+++ b/scripts/install_all.py@@ -67,7 +67,7 @@ def print_warning(message: str):def install_with_uv(requirements_file: Path, project_root: Path) -> bool:"""Try installing dependencies using uv (faster and better resolver)"""uv_path = shutil.which("uv")-+if not uv_path:# Try to install uv firstprint_info("uv not found, attempting to install uv...")@@ -85,7 +85,7 @@ def install_with_uv(requirements_file: Path, project_root: Path) -> bool:return Falseexcept Exception:return False-+print_info("Using uv for faster dependency resolution...")try:cmd = [sys.executable, "-m", "uv", "pip", "install", "-r", str(requirements_file)]@@ -106,7 +106,7 @@ def install_with_uv(requirements_file: Path, project_root: Path) -> bool:def install_with_pip_staged(requirements_file: Path, project_root: Path) -> bool:"""Install dependencies in stages to avoid resolution-too-deep error"""print_info("Using staged pip installation to avoid dependency resolution issues...")-+# Stage 1: Install core dependencies first (without complex RAG packages)core_deps = ["python-dotenv>=1.0.0",@@ -125,7 +125,7 @@ def install_with_pip_staged(requirements_file: Path, project_root: Path) -> bool"arxiv>=2.0.0","pre-commit>=3.0.0",]-+print_info("Stage 1/3: Installing core dependencies...")try:cmd = [sys.executable, "-m", "pip", "install"] + core_deps@@ -144,7 +144,7 @@ def install_with_pip_staged(requirements_file: Path, project_root: Path) -> boolexcept Exception as e:print_error(f"Error installing core dependencies: {e}")return False-+# Stage 2: Install lightrag-hkuprint_info("Stage 2/3: Installing lightrag-hku...")try:@@ -161,7 +161,7 @@ def install_with_pip_staged(requirements_file: Path, project_root: Path) -> boolprint_warning("lightrag-hku installation had issues, continuing...")except Exception as e:print_warning(f"lightrag-hku installation error: {e}")-+# Stage 3: Install raganything with special handlingprint_info("Stage 3/3: Installing raganything (this may take a while)...")try:@@ -191,7 +191,7 @@ def install_with_pip_staged(requirements_file: Path, project_root: Path) -> boolprint_warning("raganything installation had issues")except Exception as e:print_warning(f"raganything installation error: {e}")-+# Try to install any remaining optional depstry:optional_deps = ["perplexityai>=0.1.0", "dashscope>=1.14.0"]@@ -206,7 +206,7 @@ def install_with_pip_staged(requirements_file: Path, project_root: Path) -> bool)except Exception:pass-+return True@@ -227,14 +227,14 @@ def install_backend_deps(project_root: Path) -> bool:if install_with_uv(requirements_file, project_root):print_success("Backend dependencies installed successfully with uv")return True-+print_warning("uv installation failed, falling back to staged pip installation...")-+# Strategy 2: Staged pip installationif install_with_pip_staged(requirements_file, project_root):print_success("Backend dependencies installed successfully with staged pip")return True-+# Strategy 3: Direct pip install as last resortprint_warning("Staged installation had issues, trying direct pip install...")try:diff --git a/scripts/install_all.sh b/scripts/install_all.shindex ff8915bdd..7e6fb6012 100644--- a/scripts/install_all.sh+++ b/scripts/install_all.sh@@ -92,7 +92,7 @@ install_with_uv() {return 1fifi-+print_info "Using uv for faster dependency resolution..."if python -m uv pip install -r "$REQUIREMENTS_FILE"; thenreturn 0@@ -104,7 +104,7 @@ install_with_uv() {# Function to install with staged pip (avoids resolution-too-deep)install_with_pip_staged() {print_info "Using staged pip installation to avoid dependency resolution issues..."-+# Stage 1: Core dependenciesprint_info "Stage 1/3: Installing core dependencies..."if python -m pip install \@@ -128,21 +128,21 @@ install_with_pip_staged() {print_error "Failed to install core dependencies"return 1fi-+# Stage 2: lightrag-hkuprint_info "Stage 2/3: Installing lightrag-hku..."python -m pip install "lightrag-hku>=1.0.0" || print_warning "lightrag-hku installation had issues"-+# Stage 3: raganything (complex dependencies)print_info "Stage 3/3: Installing raganything (this may take a while)..."if ! python -m pip install "raganything>=0.1.0"; thenprint_warning "Standard install failed, trying with --no-deps..."python -m pip install "raganything>=0.1.0" --no-deps || print_warning "raganything installation had issues"fi-+# Optional depspython -m pip install "perplexityai>=0.1.0" "dashscope>=1.14.0" 2>/dev/null || true-+return 0}@@ -154,7 +154,7 @@ if install_with_uv; thenprint_success "Backend dependencies installed successfully with uv"elseprint_warning "uv installation failed, falling back to staged pip installation..."-+# Strategy 2: Staged pip installationif install_with_pip_staged; thenprint_success "Backend dependencies installed successfully with staged pip"diff --git a/scripts/start_web.py b/scripts/start_web.pyindex fffb31c9f..39f564348 100644--- a/scripts/start_web.py+++ b/scripts/start_web.py@@ -21,10 +21,10 @@ def print_flush(*args, **kwargs):def terminate_process_tree(process, name="Process", timeout=5):"""Terminate a process and all its children (process group).-+On Unix: Uses process group (PGID) to kill all children including uvicorn workers.On Windows: Uses taskkill /T to kill the process tree.-+Args:process: subprocess.Popen objectname: Display name for logging@@ -32,10 +32,10 @@ def terminate_process_tree(process, name="Process", timeout=5):"""if process is None or process.poll() is not None:return # Process already terminated-+pid = process.pidprint_flush(f"🛑 Stopping {name} (PID: {pid})...")-+try:if os.name == "nt":# Windows: Use taskkill with /T to kill process tree@@ -48,7 +48,7 @@ def terminate_process_tree(process, name="Process", timeout=5):else:# Unix: Kill the entire process grouppgid = os.getpgid(pid)-+# Step 1: Send SIGTERM to the process group for graceful shutdowntry:os.killpg(pgid, signal.SIGTERM)@@ -58,9 +58,9 @@ def terminate_process_tree(process, name="Process", timeout=5):returnexcept PermissionError:# Fallback: try to terminate just the main process- print_flush(f" Cannot kill process group, trying single process")+ print_flush(" Cannot kill process group, trying single process")process.terminate()-+# Step 2: Wait for graceful terminationtry:process.wait(timeout=timeout)@@ -68,14 +68,14 @@ def terminate_process_tree(process, name="Process", timeout=5):returnexcept subprocess.TimeoutExpired:print_flush(f" ⚠️ {name} did not terminate in {timeout}s, sending SIGKILL...")-+# Step 3: Force kill with SIGKILLtry:os.killpg(pgid, signal.SIGKILL)process.wait(timeout=2)print_flush(f" ✅ {name} force killed")except ProcessLookupError:- print_flush(f" Process group already terminated")+ print_flush(" Process group already terminated")except Exception as e:print_flush(f" ⚠️ Error during force kill: {e}")# Last resort: try to kill just the main process@@ -84,7 +84,7 @@ def terminate_process_tree(process, name="Process", timeout=5):process.wait(timeout=2)except Exception:pass-+except Exception as e:print_flush(f" ⚠️ Error stopping {name}: {e}")@@ -152,11 +152,11 @@ def start_backend():"errors": "replace","env": env,}-+# On Unix, create a new session so we can kill the entire process groupif os.name != "nt":popen_kwargs["start_new_session"] = True-+process = subprocess.Popen(cmd, **popen_kwargs)# Start a thread to output logs in real-time@@ -294,7 +294,7 @@ def start_frontend():env["PYTHONLEGACYWINDOWSSTDIO"] = "0"npm_cmd = shutil.which("npm") or "npm"-+# Use start_new_session=True on Unix to create a new process group# This allows us to kill all child processes (including Next.js workers) at oncepopen_kwargs = {@@ -308,11 +308,11 @@ def start_frontend():"encoding": "utf-8","errors": "replace",}-+# On Unix, create a new session so we can kill the entire process groupif os.name != "nt":popen_kwargs["start_new_session"] = True-+frontend_process = subprocess.Popen([npm_cmd, "run", "dev", "--", "-p", str(frontend_port)],**popen_kwargs,@@ -440,5 +440,5 @@ if __name__ == "__main__":# including uvicorn workers and Next.js child processesterminate_process_tree(backend, name="Backend", timeout=5)terminate_process_tree(frontend, name="Frontend", timeout=5)-+print_flush("✅ All services stopped.")