UI: Display error logs on VM crash. Fixed inspect_vm problem.
This commit is contained in:
@@ -18,7 +18,7 @@ from collections.abc import Callable
|
||||
# Kill the new process and all its children by sending a SIGTERM signal to the process group
|
||||
def _kill_group(proc: mp.Process) -> None:
|
||||
pid = proc.pid
|
||||
if proc.is_alive():
|
||||
if proc.is_alive() and pid:
|
||||
os.killpg(pid, signal.SIGTERM)
|
||||
else:
|
||||
print(f"Process {proc.name} with pid {pid} is already dead", file=sys.stderr)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import sys
|
||||
import tempfile
|
||||
import weakref
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
from typing import Any, ClassVar
|
||||
|
||||
@@ -18,12 +16,12 @@ from clan_vm_manager.models.interfaces import VMStatus
|
||||
from .executor import MPProcess, spawn
|
||||
|
||||
gi.require_version("Gtk", "4.0")
|
||||
import threading
|
||||
|
||||
from gi.repository import Gio, GLib, GObject
|
||||
import logging
|
||||
import multiprocessing as mp
|
||||
import threading
|
||||
|
||||
from clan_cli.machines.machines import Machine
|
||||
from gi.repository import Gio, GLib, GObject
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -57,11 +55,9 @@ class VM(GObject.Object):
|
||||
return
|
||||
machine = Machine(
|
||||
name=self.data.flake.flake_attr,
|
||||
flake=self.data.flake.flake_url,
|
||||
)
|
||||
vm = vms.run.inspect_vm(
|
||||
machine
|
||||
flake=Path(self.data.flake.flake_url),
|
||||
)
|
||||
vm = vms.run.inspect_vm(machine)
|
||||
self.process = spawn(
|
||||
on_except=None,
|
||||
log_dir=Path(str(self.log_dir.name)),
|
||||
@@ -91,7 +87,7 @@ class VM(GObject.Object):
|
||||
self._last_liveness = self.is_running()
|
||||
|
||||
# If the VM was running and now it is not, remove the watcher
|
||||
if prev_liveness == True and not self.is_running():
|
||||
if prev_liveness and not self.is_running():
|
||||
return GLib.SOURCE_REMOVE
|
||||
|
||||
return GLib.SOURCE_CONTINUE
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from collections.abc import Callable
|
||||
from functools import partial
|
||||
|
||||
import gi
|
||||
from clan_cli.history.add import HistoryEntry
|
||||
|
||||
@@ -7,7 +8,7 @@ from clan_vm_manager.models.use_join import Join, JoinValue
|
||||
from clan_vm_manager.models.use_views import Views
|
||||
|
||||
gi.require_version("Adw", "1")
|
||||
from gi.repository import Adw, Gdk, Gio, GObject, Gtk
|
||||
from gi.repository import Adw, Gio, GObject, Gtk
|
||||
|
||||
from clan_vm_manager.models.use_vms import VM, VMS
|
||||
|
||||
@@ -77,7 +78,7 @@ class ClanList(Gtk.Box):
|
||||
boxed_list.remove_css_class("no-shadow")
|
||||
flake = vm.data.flake
|
||||
row = Adw.ActionRow()
|
||||
|
||||
|
||||
# Title
|
||||
row.set_title(flake.clan_name)
|
||||
|
||||
@@ -144,22 +145,18 @@ class ClanList(Gtk.Box):
|
||||
|
||||
return row
|
||||
|
||||
|
||||
def show_error_dialog(self, error: str) -> None:
|
||||
p = Views.use().main_window
|
||||
|
||||
# app = Gio.Application.get_default()
|
||||
# p = Gtk.Application.get_active_window(app)
|
||||
|
||||
dialog = Adw.MessageDialog(
|
||||
heading="Error"
|
||||
)
|
||||
dialog = Adw.MessageDialog(heading="Error")
|
||||
dialog.add_response("ok", "ok")
|
||||
dialog.set_body(error)
|
||||
dialog.set_transient_for(p) # set the parent window of the dialog
|
||||
dialog.set_transient_for(p) # set the parent window of the dialog
|
||||
dialog.choose()
|
||||
|
||||
|
||||
def on_trust_clicked(self, item: JoinValue, widget: Gtk.Widget) -> None:
|
||||
def on_join(_history: list[HistoryEntry]) -> None:
|
||||
VMS.use().refresh()
|
||||
@@ -189,14 +186,9 @@ class ClanList(Gtk.Box):
|
||||
row.set_state(True)
|
||||
vm.stop()
|
||||
|
||||
|
||||
|
||||
def vm_status_changed(self, switch: Gtk.Switch, vm: VM, _vm: VM) -> None:
|
||||
switch.set_active(vm.is_running())
|
||||
switch.set_state(vm.is_running())
|
||||
|
||||
if vm.process and vm.process.proc.exitcode != 0:
|
||||
print(f"====== {vm.is_running()}")
|
||||
if not vm.is_running() and vm.process.proc.exitcode != 0:
|
||||
self.show_error_dialog(vm.read_log())
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user