Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

improve install scripts and session management

Bingxi Zhaob9cd3ed4c659
diff --git a/scripts/install_all.py b/scripts/install_all.py
index 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 first
print_info("uv not found, attempting to install uv...")
@@ -85,7 +85,7 @@ def install_with_uv(requirements_file: Path, project_root: Path) -> bool:
return False
except 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) -> bool
except Exception as e:
print_error(f"Error installing core dependencies: {e}")
return False
-
+
# Stage 2: Install lightrag-hku
print_info("Stage 2/3: Installing lightrag-hku...")
try:
@@ -161,7 +161,7 @@ def install_with_pip_staged(requirements_file: Path, project_root: Path) -> bool
print_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 handling
print_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) -> bool
print_warning("raganything installation had issues")
except Exception as e:
print_warning(f"raganything installation error: {e}")
-
+
# Try to install any remaining optional deps
try:
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 installation
if 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 resort
print_warning("Staged installation had issues, trying direct pip install...")
try:
diff --git a/scripts/install_all.sh b/scripts/install_all.sh
index ff8915bdd..7e6fb6012 100644
--- a/scripts/install_all.sh
+++ b/scripts/install_all.sh
@@ -92,7 +92,7 @@ install_with_uv() {
return 1
fi
fi
-
+
print_info "Using uv for faster dependency resolution..."
if python -m uv pip install -r "$REQUIREMENTS_FILE"; then
return 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 dependencies
print_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 1
fi
-
+
# Stage 2: lightrag-hku
print_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"; then
print_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 deps
python -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; then
print_success "Backend dependencies installed successfully with uv"
else
print_warning "uv installation failed, falling back to staged pip installation..."
-
+
# Strategy 2: Staged pip installation
if install_with_pip_staged; then
print_success "Backend dependencies installed successfully with staged pip"
diff --git a/scripts/start_web.py b/scripts/start_web.py
index 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 object
name: 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.pid
print_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 group
pgid = os.getpgid(pid)
-
+
# Step 1: Send SIGTERM to the process group for graceful shutdown
try:
os.killpg(pgid, signal.SIGTERM)
@@ -58,9 +58,9 @@ def terminate_process_tree(process, name="Process", timeout=5):
return
except 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 termination
try:
process.wait(timeout=timeout)
@@ -68,14 +68,14 @@ def terminate_process_tree(process, name="Process", timeout=5):
return
except subprocess.TimeoutExpired:
print_flush(f" ⚠️ {name} did not terminate in {timeout}s, sending SIGKILL...")
-
+
# Step 3: Force kill with SIGKILL
try:
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 group
if 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 once
popen_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 group
if 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 processes
terminate_process_tree(backend, name="Backend", timeout=5)
terminate_process_tree(frontend, name="Frontend", timeout=5)
-
+
print_flush("✅ All services stopped.")