Successfully wait for VM to start, and then move on in the UI

This commit is contained in:
Micah Lee 2021-07-01 15:52:19 -07:00
parent 29a148d211
commit 1f1bb2b353
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
3 changed files with 29 additions and 19 deletions

View file

@ -101,7 +101,7 @@ class MainWindow(QtWidgets.QMainWindow):
def vm_started(self):
self.waiting_widget.hide()
self.doc_selection_widget.show
self.doc_selection_widget.show()
def document_selected(self):
self.doc_selection_widget.hide()

View file

@ -212,10 +212,11 @@ class SettingsWidget(QtWidgets.QWidget):
"ocr", self.ocr_checkbox.checkState() == QtCore.Qt.Checked
)
self.global_common.settings.set("ocr_language", self.ocr_combobox.currentText())
if platform.system() != "Windows":
if platform.system() == "Darwin" or platform.system() == "Linux":
self.global_common.settings.set(
"open", self.open_checkbox.checkState() == QtCore.Qt.Checked
)
if platform.system() == "Linux":
self.global_common.settings.set(
"open_app", self.open_combobox.currentText()
)

View file

@ -218,11 +218,7 @@ class Vm(QtCore.QObject):
]
args_str = " ".join(pipes.quote(s) for s in args)
print("> " + args_str)
self.hyperkit_p = subprocess.Popen(
args,
# stdout=sys.stdout,
# stderr=subprocess.STDOUT,
)
self.hyperkit_p = subprocess.Popen(args)
# Get the sshd PID
with open(self.sshd_pid_path) as f:
@ -240,11 +236,11 @@ class Vm(QtCore.QObject):
def vm_connected(self):
self.state = self.STATE_ON
self.vm_state_change.emit()
self.vm_state_change.emit(self.state)
def vm_timeout(self):
self.state = self.STATE_FAIL
self.vm_state_change.emit()
self.vm_state_change.emit(self.state)
def restart(self):
self.stop()
@ -293,12 +289,25 @@ class WaitForSsh(QtCore.QThread):
def run(self):
# Wait for the SSH port to be open
success = False
timeout_seconds = 45
start_ts = time.time()
while True:
sock = socket.socket()
sock.settimeout(timeout_seconds)
try:
sock.connect(("127.0.0.1", int(self.ssh_port)))
self.connected.emit()
sock.close()
except socket.timeout:
success = True
print("ssh port open!")
break
except Exception:
print("ssh port closed ...")
pass
time.sleep(2)
if time.time() - start_ts >= timeout_seconds:
self.timeout.emit()
break
if success:
self.connected.emit()