@@ -62,19 +62,23 @@ def can_preload(self) -> bool:
62
62
def on_feature_pre_set_preload_dispvm_max (
63
63
self , event , feature , value , oldvalue = None
64
64
): # pylint: disable=unused-argument
65
- if not value :
66
- value = "0"
65
+ value = value or "0"
67
66
if not value .isdigit ():
68
67
raise qubes .exc .QubesValueError (
69
68
"Invalid preload-dispvm-max value: not a digit"
70
69
)
71
- if not oldvalue :
72
- oldvalue = 0
70
+
71
+ @qubes .events .handler ("domain-feature-set:preload-dispvm-max" )
72
+ def on_feature_set_preload_dispvm_max (
73
+ self , event , feature , value , oldvalue = None
74
+ ): # pylint: disable=unused-argument
75
+ value = value or 0
76
+ oldvalue = oldvalue or 0
73
77
oldvalue = int (oldvalue )
74
78
value = int (value )
75
79
if value > oldvalue or (value == oldvalue and self .can_preload ()):
76
80
# Also try to preload qubes when value hasn't changed so the loop
77
- # can start on a system that is already running but preload qubes
81
+ # can start on a system that is already running but preloaded qubes
78
82
# were killed, such as with 'qvm-shutdown --all'.
79
83
asyncio .ensure_future (
80
84
self .fire_event_async ("domain-preloaded-dispvm-start" )
@@ -86,8 +90,9 @@ def on_feature_pre_set_preload_dispvm_max(
86
90
new_preload = old_preload [:value ]
87
91
self .features ["preload-dispvm" ] = " " .join (new_preload or [])
88
92
for unwanted_disp in old_preload [value :]:
89
- dispvm = self .app .domains [unwanted_disp ]
90
- asyncio .ensure_future (dispvm .cleanup ())
93
+ if unwanted_disp in self .app .domains :
94
+ dispvm = self .app .domains [unwanted_disp ]
95
+ asyncio .ensure_future (dispvm .cleanup ())
91
96
92
97
@qubes .events .handler ("domain-feature-pre-set:preload-dispvm" )
93
98
def on_feature_pre_set_preload_dispvm (
@@ -189,6 +194,11 @@ async def on_domain_preloaded_dispvm_used(
189
194
"""
190
195
event = event .removeprefix ("domain-preloaded-dispvm-" )
191
196
if event == "autostart" :
197
+ old_preload = self .get_feat_preload ()
198
+ for unwanted_name in old_preload :
199
+ if unwanted_name in self .app .domains :
200
+ unwanted_dispvm = self .app .domains [unwanted_name ]
201
+ asyncio .ensure_future (unwanted_dispvm .cleanup ())
192
202
self .features ["preload-dispvm" ] = ""
193
203
if not self .can_preload ():
194
204
return
0 commit comments