Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/project/bin/run-project.py
Views: 687
#!/usr/bin/env python1"""2This is a script that is useful for debugging why a project crashes3on startup when logfiles are not sufficient.45When a project starts the hub also writes a file ~/.smc/launch-param.json,6where ~ is the HOME directory of the project. This launch-params.json7records the command, args, environment and working directory used to8launch the project. Using the script you're reading now, you can9manually launch the project, but in the foreground in your terminal,10and see what's going on when it "mysteriously crashes".1112To use this script:1314./run-project.py /path/to/launch-params.json1516DO NOT expect to interact with a project running this way from your17frontend browser client. That's not going to work, because the hub18will try to start the project again (thus deleting and recreating ~/.smc).19The purpose of this script is just to help in figuring out why a project20starts up and then JUST CRASHES for mysterious reasons.2122**It won't help with anything else yet.**23"""2425import json, subprocess, os, sys262728def run_command_with_params(params):29# Get the command, args, and cwd from the params30cmd = params["cmd"]31args = params["args"]32args = [x for x in args if 'daemon' not in x]33cwd = params["cwd"]3435# Get the environment variables from the params36env = params["env"]37env['DEBUG'] = '*'38env['DEBUG_CONSOLE'] = 'yes'3940# Convert the environment dictionary to a list of key=value strings41env_list = [f"{key}={value}" for key, value in env.items()]4243try:44# Run the command with the specified arguments and environment in the given cwd45subprocess.run([cmd] + args,46cwd=cwd,47env=dict(os.environ, **env),48check=True)49except subprocess.CalledProcessError as e:50print(f"Command execution failed with error code {e.returncode}.")51# Handle the error as needed525354if __name__ == "__main__":55if len(sys.argv) < 2:56print(f"USAGE: {sys.argv[0]} /path/to/launch-params.json")57sys.exit(1)58try:59# Read the JSON data from the file60with open(sys.argv[1], "r") as file:61params = json.load(file)62print(params)63run_command_with_params(params)64except FileNotFoundError:65print("File 'sys.argv[1]' not found.")66except json.JSONDecodeError:67print("Error parsing JSON data from the file.")686970