Skip to content

Commit 6d54a90

Browse files
committed
Handle CancelledError in SSH interaction
1 parent 9a75cf7 commit 6d54a90

1 file changed

Lines changed: 9 additions & 14 deletions

File tree

src/prompt_toolkit/contrib/ssh/server.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ def __init__(
3434
self.app_session: AppSession | None = None
3535

3636
# PipInput object, for sending input in the CLI.
37-
# (This is something that we can use in the prompt_toolkit event loop, but still write data in manually.)
37+
# (This is something that we can use in the prompt_toolkit event loop,
38+
# but still write date in manually.)
3839
self._input: PipeInput | None = None
3940
self._output: Vt100_Output | None = None
4041

41-
# Output object. Don't render to the real stdout, but write everything in the SSH channel.
42+
# Output object. Don't render to the real stdout, but write everything
43+
# in the SSH channel.
4244
class Stdout:
4345
def write(s, data: str) -> None:
4446
try:
@@ -85,7 +87,8 @@ async def _interact(self) -> None:
8587
raise Exception("`_interact` called before `connection_made`.")
8688

8789
if hasattr(self._chan, "set_line_mode") and self._chan._editor is not None:
88-
# Disable the line editing provided by asyncssh. Prompt_toolkit provides the line editing.
90+
# Disable the line editing provided by asyncssh. Prompt_toolkit
91+
# provides the line editing.
8992
self._chan.set_line_mode(False)
9093

9194
term = self._chan.get_terminal_type()
@@ -106,16 +109,12 @@ async def _interact(self) -> None:
106109
pass
107110

108111
except Exception:
109-
# Unexpected application error.
110112
traceback.print_exc()
111113

112114
finally:
113115
# Close the connection.
114-
if self._chan is not None:
115-
self._chan.close()
116-
117-
if self._input is not None:
118-
self._input.close()
116+
self._chan.close()
117+
self._input.close()
119118

120119
def terminal_size_changed(
121120
self, width: int, height: int, pixwidth: object, pixheight: object
@@ -184,8 +183,4 @@ def begin_auth(self, username: str) -> bool:
184183
return False
185184

186185
def session_requested(self) -> PromptToolkitSSHSession:
187-
return PromptToolkitSSHSession(
188-
self.interact,
189-
enable_cpr=self.enable_cpr,
190-
)
191-
186+
return PromptToolkitSSHSession(self.interact, enable_cpr=self.enable_cpr)

0 commit comments

Comments
 (0)