refactor: Add LAST_CAST_ADDRESS and streamline subprocess error handling
This commit is contained in:
8
main.py
8
main.py
@@ -6,8 +6,8 @@ logging.basicConfig(
|
|||||||
|
|
||||||
from flask import Flask, request
|
from flask import Flask, request
|
||||||
|
|
||||||
# Constants
|
|
||||||
AUTO_STOP_TIMEOUT_SECONDS = 3600 # 1 hour
|
AUTO_STOP_TIMEOUT_SECONDS = 3600 # 1 hour
|
||||||
|
LAST_CAST_ADDRESS = None
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
auto_stop_timer = None # Timer for automatic VNC stop
|
auto_stop_timer = None # Timer for automatic VNC stop
|
||||||
@@ -63,10 +63,6 @@ def cast_machine(ip_address):
|
|||||||
# Use Popen to run the command in the background (non-blocking)
|
# Use Popen to run the command in the background (non-blocking)
|
||||||
subprocess.Popen(command, shell=True)
|
subprocess.Popen(command, shell=True)
|
||||||
logging.info(f"Command '{command}' launched successfully.")
|
logging.info(f"Command '{command}' launched successfully.")
|
||||||
except FileNotFoundError:
|
|
||||||
# This error is more likely if the shell itself (e.g., /bin/sh) is not found,
|
|
||||||
# or if 'xtightvncviewer' is not in PATH and the shell fails to find it.
|
|
||||||
logging.error(f"Failed to launch VNC for {ip_address}: Shell or VNC command might not be found. Ensure xtightvncviewer is in PATH and shell is available.")
|
|
||||||
except Exception as e: # Catch other potential errors during Popen
|
except Exception as e: # Catch other potential errors during Popen
|
||||||
logging.error(f"An error occurred while launching VNC for {ip_address} with Popen: {e}")
|
logging.error(f"An error occurred while launching VNC for {ip_address} with Popen: {e}")
|
||||||
|
|
||||||
@@ -87,8 +83,6 @@ def kill_vnc():
|
|||||||
if "no process found" in result.stderr.lower():
|
if "no process found" in result.stderr.lower():
|
||||||
logging.info("No xtightvncviewer processes were found to kill.")
|
logging.info("No xtightvncviewer processes were found to kill.")
|
||||||
|
|
||||||
except FileNotFoundError:
|
|
||||||
logging.error(f"Command not found: killall. Please ensure it is installed and in PATH.")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"An unexpected error occurred while trying to run killall: {e}")
|
logging.error(f"An unexpected error occurred while trying to run killall: {e}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user