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 += [
type(self).__name__.lower(), # script name ?
]
output(' '.join(argv), 'EXECUTION')
output(' '.join(argv), 'EXECUTION', flush=True)
proc = await asyncio.create_subprocess_shell(
shlex.join(argv),

View File

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

View File

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