From f111ffa1dcf26c4bfc0dc07d74f69fe405ba1f47 Mon Sep 17 00:00:00 2001 From: edschuy95 Date: Thu, 22 Jan 2026 20:11:47 -0500 Subject: [PATCH] . --- RA3MP3Playback.pyw | 54 ++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/RA3MP3Playback.pyw b/RA3MP3Playback.pyw index e20922a..72a7bbf 100644 --- a/RA3MP3Playback.pyw +++ b/RA3MP3Playback.pyw @@ -23,7 +23,7 @@ import pygame shutdown_event = threading.Event() # ========================= CONFIG ========================= -DEBUG = False # Set True to enable debug overrides +DEBUG = True # Set True to enable debug overrides # Default paths (used if not in debug mode) DEFAULT_WIN_GAME_EXE = r"./qgame.dll" @@ -644,58 +644,50 @@ def game_launch(gameargs): creationflags=subprocess.CREATE_NO_WINDOW ) master_fd = None + + # Start monitoring in background thread + monitor_thread = threading.Thread(target=monitor_game, args=(pty_proc,)) + monitor_thread.start() + else: master_fd, slave_fd = pty.openpty() - # Close all file descriptors except the pty - # This prevents inheritance of file manager's stdin/stdout - max_fd = 1024 # Reasonable upper limit - for fd in range(3, max_fd): - try: - os.close(fd) - except OSError: - pass - pty_proc = subprocess.Popen( [game_exe, "+set", "ttycon", "1"] + gameargs, stdin=slave_fd, stdout=slave_fd, stderr=slave_fd, - close_fds=True, - # Don't let the child process be affected by parent's terminal - preexec_fn=os.setsid if hasattr(os, 'setsid') else None + close_fds=True ) os.close(slave_fd) + # Start monitoring in background thread + monitor_thread = threading.Thread(target=monitor_game_pty, args=(master_fd,)) + monitor_thread.start() + # Monitor the game output try: - if os.name == "nt": - monitor_game(pty_proc) - else: - monitor_game_pty(master_fd) + while True: + # Check if the game process is still running + if pty_proc.poll() is not None: + # Process has ended + break + + # Small sleep to prevent busy waiting + time.sleep(0.1) + # if os.name == "nt": + # monitor_game(pty_proc) + # else: + # monitor_game_pty(master_fd) except KeyboardInterrupt: print("Exiting...") finally: stop_flag.set() stop_playback() if pty_proc: - try: - pty_proc.stdin.close() - except: - pass - - try: - pty_proc.stdout.close() - except: - pass - try: pty_proc.terminate() - except: - pass - - try: pty_proc.wait(timeout=5) except: pass