Skip to content

Commit 6b3b1ce

Browse files
authored
Fix race condition during shutdoen under Windows (#2864)
The terminal writer thread could send escape sequences when the terminal was unable to process then; i.e. when not in virtual mode. The following fixes have been made. - Switch the terminal to virtual mode before the writer thread is started and any control sequences are queued to the writer thread. - Wait for the writer thread to finish before switching the terminal out of virtual mode.
1 parent ac5e2d1 commit 6b3b1ce

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/textual/drivers/windows_driver.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ def start_application_mode(self) -> None:
7676
"""Start application mode."""
7777
loop = asyncio.get_running_loop()
7878

79+
self._restore_console = win32.enable_application_mode()
80+
7981
self._writer_thread = WriterThread(self._file)
8082
self._writer_thread.start()
8183

82-
self._restore_console = win32.enable_application_mode()
83-
8484
self.write("\x1b[?1049h") # Enable alt screen
8585
self._enable_mouse_support()
8686
self.write("\x1b[?25l") # Hide cursor
@@ -110,8 +110,6 @@ def stop_application_mode(self) -> None:
110110
"""Stop application mode, restore state."""
111111
self._disable_bracketed_paste()
112112
self.disable_input()
113-
if self._restore_console:
114-
self._restore_console()
115113

116114
# Disable alt screen, show cursor
117115
self.write("\x1b[?1049l" + "\x1b[?25h")
@@ -121,3 +119,5 @@ def close(self) -> None:
121119
"""Perform cleanup."""
122120
if self._writer_thread is not None:
123121
self._writer_thread.stop()
122+
if self._restore_console:
123+
self._restore_console()

0 commit comments

Comments
 (0)