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.
This commit is contained in:
paul-ollis
2023-07-03 15:32:10 +01:00
committed by GitHub
parent ac5e2d19a7
commit 6b3b1ce67f

View File

@@ -76,11 +76,11 @@ class WindowsDriver(Driver):
"""Start application mode."""
loop = asyncio.get_running_loop()
self._restore_console = win32.enable_application_mode()
self._writer_thread = WriterThread(self._file)
self._writer_thread.start()
self._restore_console = win32.enable_application_mode()
self.write("\x1b[?1049h") # Enable alt screen
self._enable_mouse_support()
self.write("\x1b[?25l") # Hide cursor
@@ -110,8 +110,6 @@ class WindowsDriver(Driver):
"""Stop application mode, restore state."""
self._disable_bracketed_paste()
self.disable_input()
if self._restore_console:
self._restore_console()
# Disable alt screen, show cursor
self.write("\x1b[?1049l" + "\x1b[?25h")
@@ -121,3 +119,5 @@ class WindowsDriver(Driver):
"""Perform cleanup."""
if self._writer_thread is not None:
self._writer_thread.stop()
if self._restore_console:
self._restore_console()