# run.py import subprocess import sys import os import signal import atexit bg_process = None def cleanup(): """Ensure background process is terminated on script exit.""" global bg_process if bg_process and bg_process.poll() is None: print("\nšŸ›‘ Terminating background data pipeline...") try: os.kill(bg_process.pid, signal.SIGTERM) bg_process.wait(timeout=5) except (ProcessLookupError, subprocess.TimeoutExpired): print("āš ļø Force killing background process...") bg_process.kill() print("āœ… Pipeline terminated.") def run_command(command_args, description): """Runs a setup command using its file path and exits if it fails.""" print(f"šŸš€ {description}...") try: # --- FIX IS HERE: We now run the script by its file path directly --- result = subprocess.run( [sys.executable] + command_args, check=True, capture_output=True, text=True ) print(f"āœ… {description} complete.") except subprocess.CalledProcessError as e: print(f"āŒ ERROR: {description} failed.") print(e.stderr) # Print the actual error from the script sys.exit(1) def main(): atexit.register(cleanup) # --- FIX IS HERE: We pass the file paths as a list --- run_command(["database/database_setup.py"], "Initializing database") run_command(["scripts/seed_db.py"], "Seeding initial data") # Start the background data pipeline print("šŸ“” Starting background data pipeline...") global bg_process bg_process = subprocess.Popen([sys.executable, "main.py"]) print(f"āœ… Data pipeline started with PID: {bg_process.pid}") # Start the Streamlit app print("šŸ“Š Starting Streamlit dashboard...") try: subprocess.run( ["streamlit", "run", "app.py", "--server.port", "8501", "--server.headless", "true"], check=True ) finally: cleanup() if __name__ == "__main__": main()