From 7e337205d70578184fba2b2449f4ec11babec9e3 Mon Sep 17 00:00:00 2001 From: "g@localhost.localdomain" <> Date: Sat, 2 Dec 2006 18:36:09 +0100 Subject: [PATCH] Print unfinished lines after some delay --- gsh/main.py | 3 ++- gsh/remote_dispatcher.py | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gsh/main.py b/gsh/main.py index 89b3a91..4087995 100644 --- a/gsh/main.py +++ b/gsh/main.py @@ -85,7 +85,8 @@ def main_loop(): show_status(completed, total) if remote_dispatcher.all_terminated(): raise asyncore.ExitNow - asyncore.loop(count=1) + asyncore.loop(count=1, timeout=None) + remote_dispatcher.handle_unfinished_lines() except KeyboardInterrupt: control_shell.launch() except asyncore.ExitNow: diff --git a/gsh/remote_dispatcher.py b/gsh/remote_dispatcher.py index dbc9808..8086fb8 100644 --- a/gsh/remote_dispatcher.py +++ b/gsh/remote_dispatcher.py @@ -22,6 +22,7 @@ import pty import random import signal import sys +import time from gsh.buffered_dispatcher import buffered_dispatcher from gsh.console import console_output @@ -54,6 +55,21 @@ def count_completed_processes(): completed_processes += 1 return completed_processes, total +def handle_unfinished_lines(): + for r in all_instances(): + if r.read_buffer: + break + else: + # No unfinished lines + return + + begin = time.time() + asyncore.loop(count=1,timeout=0.2) + duration = time.time() - begin + if duration >= 0.15: + for r in all_instances(): + r.print_unfinished_line() + def dispatch_termination_to_all(): for r in all_instances(): r.dispatch_termination() @@ -212,6 +228,15 @@ class remote_dispatcher(buffered_dispatcher): self.read_buffer = self.read_buffer[lf_pos + 1:] lf_pos = self.read_buffer.find('\n') + def print_unfinished_line(self): + if self.state in (STATE_EXPECTING_LINE, STATE_RUNNING): + if not self.options.print_first or \ + self.state == STATE_EXPECTING_LINE: + line = self.read_buffer + '\n' + self.read_buffer = '' + self.log(line) + console_output(self.name + ': ' + line) + def writable(self): return self.active and buffered_dispatcher.writable(self) -- 2.11.4.GIT