Handle abort in exclusive output state correctly

If the event loop is stopped while something holds the exclusive output, the
"log" singleton is now reset so the main thread can print a few more messages
before exiting.
This commit is contained in:
Joscha
2021-05-22 18:58:00 +02:00
parent 552cd82802
commit afac22c562
2 changed files with 18 additions and 1 deletions

View File

@ -97,12 +97,28 @@ class Log:
self.print(line)
self._lines = []
def unlock(self) -> None:
"""
Get rid of an exclusive output state.
This function is meant to let PFERD print log messages after the event
loop was forcibly stopped and if it will not be started up again. After
this is called, it is not safe to use any functions except the logging
functions (print, warn, ...).
"""
self._progress_suspended = False
for line in self._lines:
self.print(line)
def print(self, text: str) -> None:
if self._progress_suspended:
self._lines.append(text)
else:
self.console.print(text)
# TODO Print errors (and warnings?) to stderr
def warn(self, text: str) -> None:
self.print(f"[bold bright_red]Warning[/] {escape(text)}")