diff --git a/pagebot.py b/pagebot.py index 346126f..3f74b73 100644 --- a/pagebot.py +++ b/pagebot.py @@ -112,6 +112,13 @@ async def upload_to_discord(mp4_file, text): TTD_TIMEOUT = getattr(secrets_file, 'ttd_timeout', 900) +def kill_process_tree(pid): + try: + subprocess.run(['taskkill', '/F', '/T', '/PID', str(pid)], + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + except Exception as e: + print(f"Error killing process tree: {e}") + def launch_and_watch(program_path): global last_file_time program_directory = os.path.dirname(program_path) @@ -125,11 +132,11 @@ def launch_and_watch(program_path): except subprocess.TimeoutExpired: if time.time() - last_file_time > TTD_TIMEOUT: print("TTD appears to have locked up (no new files in 15 minutes). Restarting...") - process.kill() - process.wait() + kill_process_tree(process.pid) break - if process.returncode != 0: + if process.returncode is None or process.returncode != 0: print("TTD has crashed. Relaunching...") + kill_process_tree(process.pid) else: print("TTD has exited normally.") break