From 0ac3261f97aa17b1e01eb4b1d060a79e525e11d0 Mon Sep 17 00:00:00 2001 From: majmongoose Date: Fri, 21 Aug 2026 11:39:24 -0400 Subject: [PATCH] Update pagebot.py --- pagebot.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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