forked from LBRYCommunity/lbry-sdk
capture stderr before process pool starts
This commit is contained in:
parent
5883c9bc6c
commit
192c79c49c
1 changed files with 11 additions and 4 deletions
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue