capture stderr before process pool starts

This commit is contained in:
Lex Berezhny 2020-07-01 18:32:20 -04:00
parent 5883c9bc6c
commit 192c79c49c

View file

@ -43,8 +43,8 @@ class RedirectOutput:
def release(self): def release(self):
self.__exit__(None, None, None) self.__exit__(None, None, None)
def flush(self, writer, last=False): def flush(self, writer, force=False):
if not last and (time.time() - self.last_flush) < 5: if not force and (time.time() - self.last_flush) < 5:
return return
self.file.seek(self.last_read) self.file.seek(self.last_read)
for line in self.file.readlines(): for line in self.file.readlines():
@ -117,6 +117,15 @@ class Advanced(Basic):
self.block_readers = 0 self.block_readers = 0
self.stderr = RedirectOutput('stderr') self.stderr = RedirectOutput('stderr')
def starting(self):
self.stderr.capture()
super().starting()
def stopping(self):
super().stopping()
self.stderr.flush(self.bars['sync'].write, True)
self.stderr.release()
def get_or_create_bar(self, name, desc, unit, total, leave=False, bar_format=None, postfix=None, position=None): def get_or_create_bar(self, name, desc, unit, total, leave=False, bar_format=None, postfix=None, position=None):
bar = self.bars.get(name) bar = self.bars.get(name)
if bar is None: if bar is None:
@ -219,13 +228,11 @@ class Advanced(Basic):
def on_sync_progress(self, event): def on_sync_progress(self, event):
e, d = event['event'], event.get('data', {}) e, d = event['event'], event.get('data', {})
if e.endswith("sync.start"): if e.endswith("sync.start"):
self.stderr.capture()
self.sync_start(d) self.sync_start(d)
self.stderr.flush(self.bars['sync'].write) self.stderr.flush(self.bars['sync'].write)
elif e.endswith("sync.complete"): elif e.endswith("sync.complete"):
self.stderr.flush(self.bars['sync'].write, True) self.stderr.flush(self.bars['sync'].write, True)
self.sync_complete() self.sync_complete()
self.stderr.release()
else: else:
self.stderr.flush(self.bars['sync'].write) self.stderr.flush(self.bars['sync'].write)
self.update_progress(e, d) self.update_progress(e, d)