From 2e61b709962c438c12d506c563688cd4ca4598d1 Mon Sep 17 00:00:00 2001 From: Aaron Heise Date: Sun, 12 Feb 2023 01:51:58 -0600 Subject: [PATCH] Fix issue with running rnsh without proper tty (like from launch) --- rnsh/process.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/rnsh/process.py b/rnsh/process.py index 630a620..bef199b 100644 --- a/rnsh/process.py +++ b/rnsh/process.py @@ -184,7 +184,9 @@ class TTYRestorer(contextlib.AbstractContextManager): :param fd: file descriptor of tty """ self._fd = fd - self._tattr = termios.tcgetattr(self._fd) + self._tattr = None + with contextlib.suppress(termios.error): + termios.tcgetattr(self._fd) def raw(self): """ @@ -210,12 +212,13 @@ class TTYRestorer(contextlib.AbstractContextManager): """ Restore termios settings to state captured in constructor. """ - termios.tcsetattr(self._fd, termios.TCSADRAIN, self._tattr) + self.set_attr(self._tattr, termios.TCSADRAIN) def __exit__(self, __exc_type: typing.Type[BaseException], __exc_value: BaseException, __traceback: types.TracebackType) -> bool: - self.restore() - return False + with contextlib.suppress(termios.error): + self.restore() + return __exc_type is not None and issubclass(__exc_type, termios.error) async def event_wait(evt: asyncio.Event, timeout: float) -> bool: