mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-24 16:03:23 +00:00
Merge pull request #142207 from K900/fix-python-crashes-in-tests
nixos/lib/test-driver: clean up threads correctly
This commit is contained in:
commit
e7a1dea4c8
@ -6,7 +6,7 @@ from xml.sax.saxutils import XMLGenerator
|
|||||||
from colorama import Style
|
from colorama import Style
|
||||||
import queue
|
import queue
|
||||||
import io
|
import io
|
||||||
import _thread
|
import threading
|
||||||
import argparse
|
import argparse
|
||||||
import atexit
|
import atexit
|
||||||
import base64
|
import base64
|
||||||
@ -405,13 +405,14 @@ class Machine:
|
|||||||
keep_vm_state: bool
|
keep_vm_state: bool
|
||||||
allow_reboot: bool
|
allow_reboot: bool
|
||||||
|
|
||||||
process: Optional[subprocess.Popen] = None
|
process: Optional[subprocess.Popen]
|
||||||
pid: Optional[int] = None
|
pid: Optional[int]
|
||||||
monitor: Optional[socket.socket] = None
|
monitor: Optional[socket.socket]
|
||||||
shell: Optional[socket.socket] = None
|
shell: Optional[socket.socket]
|
||||||
|
serial_thread: Optional[threading.Thread]
|
||||||
|
|
||||||
booted: bool = False
|
booted: bool
|
||||||
connected: bool = False
|
connected: bool
|
||||||
# Store last serial console lines for use
|
# Store last serial console lines for use
|
||||||
# of wait_for_console_text
|
# of wait_for_console_text
|
||||||
last_lines: Queue = Queue()
|
last_lines: Queue = Queue()
|
||||||
@ -444,6 +445,15 @@ class Machine:
|
|||||||
self.cleanup_statedir()
|
self.cleanup_statedir()
|
||||||
self.state_dir.mkdir(mode=0o700, exist_ok=True)
|
self.state_dir.mkdir(mode=0o700, exist_ok=True)
|
||||||
|
|
||||||
|
self.process = None
|
||||||
|
self.pid = None
|
||||||
|
self.monitor = None
|
||||||
|
self.shell = None
|
||||||
|
self.serial_thread = None
|
||||||
|
|
||||||
|
self.booted = False
|
||||||
|
self.connected = False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_startcommand(args: Dict[str, str]) -> StartCommand:
|
def create_startcommand(args: Dict[str, str]) -> StartCommand:
|
||||||
rootlog.warning(
|
rootlog.warning(
|
||||||
@ -921,7 +931,8 @@ class Machine:
|
|||||||
self.last_lines.put(line)
|
self.last_lines.put(line)
|
||||||
self.log_serial(line)
|
self.log_serial(line)
|
||||||
|
|
||||||
_thread.start_new_thread(process_serial_output, ())
|
self.serial_thread = threading.Thread(target=process_serial_output)
|
||||||
|
self.serial_thread.start()
|
||||||
|
|
||||||
self.wait_for_monitor_prompt()
|
self.wait_for_monitor_prompt()
|
||||||
|
|
||||||
@ -1021,9 +1032,12 @@ class Machine:
|
|||||||
assert self.process
|
assert self.process
|
||||||
assert self.shell
|
assert self.shell
|
||||||
assert self.monitor
|
assert self.monitor
|
||||||
|
assert self.serial_thread
|
||||||
|
|
||||||
self.process.terminate()
|
self.process.terminate()
|
||||||
self.shell.close()
|
self.shell.close()
|
||||||
self.monitor.close()
|
self.monitor.close()
|
||||||
|
self.serial_thread.join()
|
||||||
|
|
||||||
|
|
||||||
class VLan:
|
class VLan:
|
||||||
|
Loading…
Reference in New Issue
Block a user