Clean up running processes
()
| 291 | |
| 292 | |
| 293 | def cleanup_processes(): |
| 294 | """Clean up running processes""" |
| 295 | global _backend_process, _frontend_process |
| 296 | |
| 297 | print("\nš Stopping services...") |
| 298 | |
| 299 | for name, proc in [("Backend", _backend_process), ("Frontend", _frontend_process)]: |
| 300 | if proc and proc.poll() is None: |
| 301 | try: |
| 302 | if get_platform() == "windows": |
| 303 | # Windows: use taskkill with /T to kill tree |
| 304 | subprocess.run( |
| 305 | f"taskkill /F /T /PID {proc.pid}", |
| 306 | shell=True, |
| 307 | capture_output=True, |
| 308 | ) |
| 309 | else: |
| 310 | # Unix: kill the process group |
| 311 | try: |
| 312 | os.killpg(os.getpgid(proc.pid), signal.SIGTERM) |
| 313 | proc.wait(timeout=5) |
| 314 | except Exception: |
| 315 | os.killpg(os.getpgid(proc.pid), signal.SIGKILL) |
| 316 | print(f" ā {name} stopped") |
| 317 | except Exception: |
| 318 | # Fallback: try direct terminate |
| 319 | try: |
| 320 | proc.terminate() |
| 321 | proc.wait(timeout=3) |
| 322 | print(f" ā {name} stopped") |
| 323 | except Exception: |
| 324 | try: |
| 325 | proc.kill() |
| 326 | print(f" ā {name} killed") |
| 327 | except Exception: |
| 328 | print(f" ā ļø Could not stop {name}") |
| 329 | |
| 330 | # Also clean up any orphaned processes on ports |
| 331 | time.sleep(0.5) |
| 332 | for port in [8000, 5173]: |
| 333 | if is_port_in_use(port): |
| 334 | kill_process_on_port(port) |
| 335 | |
| 336 | print("ā All services stopped") |
| 337 | |
| 338 | |
| 339 | def cleanup_cache(): |
no test coverage detected