Output flushing

This commit is contained in:
jpic 2020-02-13 15:13:23 +01:00
parent 5f740f3e72
commit c78874a7e0
3 changed files with 7 additions and 6 deletions

View File

@ -101,7 +101,7 @@ class Build(Script):
argv += [ argv += [
type(self).__name__.lower(), # script name ? type(self).__name__.lower(), # script name ?
] ]
output(' '.join(argv), 'EXECUTION') output(' '.join(argv), 'EXECUTION', flush=True)
proc = await asyncio.create_subprocess_shell( proc = await asyncio.create_subprocess_shell(
shlex.join(argv), shlex.join(argv),

View File

@ -28,7 +28,7 @@ class Output:
self.prefixes = dict() self.prefixes = dict()
self.prefix_length = 0 self.prefix_length = 0
def __call__(self, line, prefix, highlight=True): def __call__(self, line, prefix, highlight=True, flush=True):
if prefix and prefix not in self.prefixes: if prefix and prefix not in self.prefixes:
self.prefixes[prefix] = ( self.prefixes[prefix] = (
self.colors[len([*self.prefixes.keys()]) - 1] self.colors[len([*self.prefixes.keys()]) - 1]
@ -58,6 +58,9 @@ class Output:
+ self.highlight(line, highlight) + self.highlight(line, highlight)
).encode('utf8')) ).encode('utf8'))
if flush:
sys.stdout.flush()
def cmd(self, line, prefix): def cmd(self, line, prefix):
self( self(
Fore.LIGHTBLACK_EX Fore.LIGHTBLACK_EX
@ -108,7 +111,7 @@ class PrefixStreamProtocol(asyncio.subprocess.SubprocessStreamProtocol):
for line in data.split(b'\n'): for line in data.split(b'\n'):
if not line: if not line:
continue continue
output(line, self.prefix) output(line, self.prefix, flush=False)
sys.stdout.flush() sys.stdout.flush()
super().pipe_data_received(fd, data) super().pipe_data_received(fd, data)

View File

@ -70,11 +70,10 @@ class Script:
')' ')'
]), ]),
getattr(visitor, 'name', getattr(visitor, 'name',
getattr(visitable, 'name', None)) getattr(visitable, 'name', None)),
) )
if result: if result:
await result await result
sys.stdout.flush()
for prefix in ('init_', 'pre_', '', 'post_', 'clean_'): for prefix in ('init_', 'pre_', '', 'post_', 'clean_'):
method = prefix + self.name method = prefix + self.name
@ -101,7 +100,6 @@ class Script:
except Exception as e: except Exception as e:
await clean() await clean()
raise raise
sys.stdout.flush()
async def run(self, *args, **kwargs): async def run(self, *args, **kwargs):
for key, value in kwargs.items(): for key, value in kwargs.items():