mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
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:
parent
552cd82802
commit
afac22c562
@ -115,11 +115,11 @@ def main() -> None:
|
|||||||
dump_config(args, config)
|
dump_config(args, config)
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
# TODO Unset exclusive output on exceptions (if it was being held)
|
|
||||||
pferd = Pferd(config)
|
pferd = Pferd(config)
|
||||||
try:
|
try:
|
||||||
asyncio.run(pferd.run())
|
asyncio.run(pferd.run())
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
log.unlock()
|
||||||
log.explain_topic("Interrupted, exiting immediately")
|
log.explain_topic("Interrupted, exiting immediately")
|
||||||
log.explain("Open files and connections are left for the OS to clean up")
|
log.explain("Open files and connections are left for the OS to clean up")
|
||||||
log.explain("Temporary files are not cleaned up")
|
log.explain("Temporary files are not cleaned up")
|
||||||
@ -128,5 +128,6 @@ def main() -> None:
|
|||||||
# reconsider what exit code to use here.
|
# reconsider what exit code to use here.
|
||||||
exit(1)
|
exit(1)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
log.unlock()
|
||||||
log.unexpected_exception()
|
log.unexpected_exception()
|
||||||
exit(1)
|
exit(1)
|
||||||
|
@ -97,12 +97,28 @@ class Log:
|
|||||||
self.print(line)
|
self.print(line)
|
||||||
self._lines = []
|
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:
|
def print(self, text: str) -> None:
|
||||||
if self._progress_suspended:
|
if self._progress_suspended:
|
||||||
self._lines.append(text)
|
self._lines.append(text)
|
||||||
else:
|
else:
|
||||||
self.console.print(text)
|
self.console.print(text)
|
||||||
|
|
||||||
|
# TODO Print errors (and warnings?) to stderr
|
||||||
|
|
||||||
def warn(self, text: str) -> None:
|
def warn(self, text: str) -> None:
|
||||||
self.print(f"[bold bright_red]Warning[/] {escape(text)}")
|
self.print(f"[bold bright_red]Warning[/] {escape(text)}")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user