mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-05 15:41:39 +02:00
Ignore errors in various finalizers during exit
This was needed for tui loop to exit cleanly when terminal i/o breaks
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
|
||||
from collections import deque
|
||||
from contextlib import suppress
|
||||
from time import monotonic
|
||||
from types import TracebackType
|
||||
from typing import (
|
||||
@@ -94,9 +95,10 @@ class Handler:
|
||||
|
||||
def __exit__(self, etype: type, value: Exception, tb: TracebackType) -> None:
|
||||
del self.debug.fobj
|
||||
self.finalize()
|
||||
if self._image_manager is not None:
|
||||
self._image_manager.__exit__(etype, value, tb)
|
||||
with suppress(Exception):
|
||||
self.finalize()
|
||||
if self._image_manager is not None:
|
||||
self._image_manager.__exit__(etype, value, tb)
|
||||
|
||||
def initialize(self) -> None:
|
||||
pass
|
||||
|
||||
@@ -10,7 +10,7 @@ import selectors
|
||||
import signal
|
||||
import sys
|
||||
import termios
|
||||
from contextlib import contextmanager
|
||||
from contextlib import contextmanager, suppress
|
||||
from enum import Enum, IntFlag, auto
|
||||
from functools import partial
|
||||
from typing import Any, Callable, Dict, Generator, List, NamedTuple, Optional
|
||||
@@ -102,9 +102,10 @@ class TermManager:
|
||||
return self
|
||||
|
||||
def __exit__(self, *a: object) -> None:
|
||||
self.reset_state_to_original()
|
||||
close_tty(self.tty_fd, self.original_termios)
|
||||
del self.tty_fd, self.original_termios
|
||||
with suppress(Exception):
|
||||
self.reset_state_to_original()
|
||||
close_tty(self.tty_fd, self.original_termios)
|
||||
del self.tty_fd, self.original_termios
|
||||
|
||||
|
||||
class MouseButton(IntFlag):
|
||||
@@ -463,7 +464,8 @@ class Loop:
|
||||
term_manager.extra_finalize = b''.join(self.write_buf).decode('utf-8')
|
||||
if tb is not None:
|
||||
self.return_code = 1
|
||||
self._report_error_loop(tb, term_manager)
|
||||
if not handler.terminal_io_ended:
|
||||
self._report_error_loop(tb, term_manager)
|
||||
|
||||
def _report_error_loop(self, tb: str, term_manager: TermManager) -> None:
|
||||
self.loop_impl(UnhandledException(tb), term_manager)
|
||||
|
||||
Reference in New Issue
Block a user