From bdd28ab56286603e9c23a4743329dfcb9e6d976a Mon Sep 17 00:00:00 2001 From: Mathieu Comandon Date: Thu, 4 May 2017 18:25:27 -0700 Subject: [PATCH] Replace logging output with GLib IO watch --- lutris/thread.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lutris/thread.py b/lutris/thread.py index bce6da634..48743f090 100644 --- a/lutris/thread.py +++ b/lutris/thread.py @@ -111,20 +111,18 @@ class LutrisThread(threading.Thread): self.game_process = self.execute_process(self.command, env) if not self.game_process: return - for line in iter(self.game_process.stdout.readline, b''): - if not self.is_running: - break - try: - line = line.decode() - except UnicodeDecodeError: - line = '' - if not line: - continue + + GLib.io_add_watch(self.game_process.stdout, GLib.IO_IN, self.on_stdout_output) + + def on_stdout_output(self, fd, condition): + line = fd.readline().decode(errors='replace') + if line: self.stdout += line if self.debug_output: with contextlib.suppress(BlockingIOError): sys.stdout.write(line) sys.stdout.flush() + return True def run_in_terminal(self): """Write command in a script file and run it.