From 1a82934a3c5dedfcbbdf4a40b23f5b5e934fb2b6 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 9 Feb 2022 15:25:03 +0100 Subject: [PATCH] Improving SysCommandWorker() to handle buffered output. --- archinstall/lib/general.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/archinstall/lib/general.py b/archinstall/lib/general.py index cfc6425a..f2ed05ee 100644 --- a/archinstall/lib/general.py +++ b/archinstall/lib/general.py @@ -284,7 +284,13 @@ class SysCommandWorker: self.make_sure_we_are_executing() if self.child_fd: - return os.write(self.child_fd, data + (b'\n' if line_ending else b'')) + written_data = os.write(self.child_fd, data + (b'\n' if line_ending else b'')) + os.fsync(self.child_fd) + + with open('debug_write.txt', 'a') as silent_output: + silent_output.write(f'Wrote {[data + (b'\n' if line_ending else b'')]}\n') + + return written_data return 0 @@ -354,6 +360,10 @@ class SysCommandWorker: # stdout of the child_fd object. `os.read(self.child_fd, 8192)` is the # only way to get the traceback without loosing it. + # We need to flush any pending output to the parent + # otherwise it will bleed into the child: https://docs.python.org/3/library/os.html#os.execvpe + sys.stdout.flush() + self.pid, self.child_fd = pty.fork() os.chdir(old_dir)