Index: cs.py =================================================================== diff -u -re2b5bba1ace2613e8cd3ca6d997756b1b61d77a4 -r34a18ebe349364c4e0462d876d4d191bf3df8939 --- cs.py (.../cs.py) (revision e2b5bba1ace2613e8cd3ca6d997756b1b61d77a4) +++ cs.py (.../cs.py) (revision 34a18ebe349364c4e0462d876d4d191bf3df8939) @@ -30,17 +30,29 @@ if cs_proc: print("CloudSync app already running") else: - print("Starting CloudSync app with logging level {0}".format(logging_level)) - time.sleep(DELAY) + print(f"Starting CloudSync app with logging level {logging_level}") Popen(['python3', 'cloud_sync.py', str(logging_level)]) + # Keep the main process running + while True: + # Check if the subprocess is still running or perform other periodic checks + time.sleep(60) # Adjust the sleep time as needed def stop(): cs_proc_pid = get_pid() if cs_proc_pid: print("Stopping CloudSync app...") time.sleep(DELAY) - os.kill(int(cs_proc_pid), signal.SIGKILL) + try: + os.kill(int(cs_proc_pid), signal.SIGKILL) + print(f"Successfully killed process {cs_proc_pid}") + except PermissionError: + print( + f"Permission denied when trying to kill process {cs_proc_pid}") + except ProcessLookupError: + print(f"No process with PID {cs_proc_pid}") + except Exception as e: + print(f"Error killing process {cs_proc_pid}: {str(e)}") else: print("CloudSync app is not running.")