@@ -191,6 +191,7 @@ def __init__(self,
self.sock_dir, f"{self._name}.con"
)
self._console_socket: Optional[socket.socket] = None
+ self._console_file: Optional[socket.SocketIO] = None
self._remove_files: List[str] = []
self._user_killed = False
self._quit_issued = False
@@ -509,6 +510,11 @@ def _early_cleanup(self) -> None:
# If we keep the console socket open, we may deadlock waiting
# for QEMU to exit, while QEMU is waiting for the socket to
# become writable.
+ if self._console_file is not None:
+ LOG.debug("Closing console file")
+ self._console_file.close()
+ self._console_file = None
+
if self._console_socket is not None:
LOG.debug("Closing console socket")
self._console_socket.close()
@@ -874,12 +880,25 @@ def console_socket(self) -> socket.socket:
Returns a socket connected to the console
"""
if self._console_socket is None:
+ LOG.debug("Opening console socket")
self._console_socket = console_socket.ConsoleSocket(
self._console_address,
file=self._console_log_path,
drain=self._drain_console)
return self._console_socket
+ @property
+ def console_file(self) -> socket.SocketIO:
+ """
+ Returns a file associated with the console socket
+ """
+ if self._console_file is None:
+ LOG.debug("Opening console file")
+ self._console_file = self.console_socket.makefile(mode='rb',
+ buffering=0,
+ encoding='utf-8')
+ return self._console_file
+
@property
def temp_dir(self) -> str:
"""
@@ -137,7 +137,7 @@ def _console_interaction(test, success_message, failure_message,
assert not keep_sending or send_string
if vm is None:
vm = test.vm
- console = vm.console_socket.makefile(mode='rb', encoding='utf-8')
+ console = vm.console_file
console_logger = logging.getLogger('console')
while True:
if send_string: