Browse Source

f_rich_progress不吃掉python prompt; evalutor在结束之后正常消失progres bar

tags/v1.0.0alpha
yh_cc 3 years ago
parent
commit
d10c6395f2
2 changed files with 3 additions and 3 deletions
  1. +2
    -0
      fastNLP/core/controllers/evaluator.py
  2. +1
    -3
      fastNLP/core/utils/rich_progress.py

+ 2
- 0
fastNLP/core/controllers/evaluator.py View File

@@ -219,6 +219,7 @@ class Evaluator:
def remove_progress_bar(self, dataloader_name): def remove_progress_bar(self, dataloader_name):
if self.progress_bar == 'rich' and hasattr(self, '_rich_task_id'): if self.progress_bar == 'rich' and hasattr(self, '_rich_task_id'):
f_rich_progress.destroy_task(self._rich_task_id) f_rich_progress.destroy_task(self._rich_task_id)
f_rich_progress.refresh() # 使得最终的bar可以消失
delattr(self, '_rich_task_id') delattr(self, '_rich_task_id')
elif self.progress_bar == 'raw': elif self.progress_bar == 'raw':
desc = 'Evaluation ends' desc = 'Evaluation ends'
@@ -229,6 +230,7 @@ class Evaluator:
def finally_progress_bar(self): def finally_progress_bar(self):
if self.progress_bar == 'rich' and hasattr(self, '_rich_task_id'): if self.progress_bar == 'rich' and hasattr(self, '_rich_task_id'):
f_rich_progress.destroy_task(self._rich_task_id) f_rich_progress.destroy_task(self._rich_task_id)
f_rich_progress.refresh()
delattr(self, '_rich_task_id') delattr(self, '_rich_task_id')


@property @property


+ 1
- 3
fastNLP/core/utils/rich_progress.py View File

@@ -94,9 +94,6 @@ class FRichProgress(Progress, metaclass=Singleton):
self.print = self.console.print self.print = self.console.print
self.log = self.console.log self.log = self.console.log


# start new
self.start()
self.console.show_cursor(show=True)
return self return self


def set_transient(self, transient: bool = True): def set_transient(self, transient: bool = True):
@@ -154,6 +151,7 @@ class FRichProgress(Progress, metaclass=Singleton):
super().start() super().start()
self.console.show_cursor(show=True) self.console.show_cursor(show=True)



if (sys.stdin and sys.stdin.isatty()) and get_global_rank() == 0: if (sys.stdin and sys.stdin.isatty()) and get_global_rank() == 0:
f_rich_progress = FRichProgress().new_progess( f_rich_progress = FRichProgress().new_progess(
"[progress.description]{task.description}", "[progress.description]{task.description}",


Loading…
Cancel
Save